updated core to 7.58 (right after the site was hacked)
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* @file
|
||||
* CSS for Field Example.
|
||||
*/
|
||||
div.form-item table .form-type-textfield,
|
||||
div.form-item table .form-type-textfield * {
|
||||
display: inline-block;
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
name = Field Example
|
||||
description = An implementation of a field to show the Field API
|
||||
package = Example modules
|
||||
core = 7.x
|
||||
files[] = field_example.test
|
||||
|
||||
; Information added by Drupal.org packaging script on 2016-09-18
|
||||
version = "7.x-1.x-dev"
|
||||
core = "7.x"
|
||||
project = "examples"
|
||||
datestamp = "1474218553"
|
||||
|
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Install, update, and uninstall functions for the field_example module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_field_schema().
|
||||
*
|
||||
* Defines the database schema of the field, using the format used by the
|
||||
* Schema API.
|
||||
*
|
||||
* The data we will store here is just one 7-character element, even
|
||||
* though the widget presents the three portions separately.
|
||||
*
|
||||
* All implementations of hook_field_schema() must be in the module's
|
||||
* .install file.
|
||||
*
|
||||
* @see http://drupal.org/node/146939
|
||||
* @see schemaapi
|
||||
* @see hook_field_schema()
|
||||
* @ingroup field_example
|
||||
*/
|
||||
function field_example_field_schema($field) {
|
||||
$columns = array(
|
||||
'rgb' => array('type' => 'varchar', 'length' => 7, 'not null' => FALSE),
|
||||
);
|
||||
$indexes = array(
|
||||
'rgb' => array('rgb'),
|
||||
);
|
||||
return array(
|
||||
'columns' => $columns,
|
||||
'indexes' => $indexes,
|
||||
);
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* @file
|
||||
* Javascript for Field Example.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides a farbtastic colorpicker for the fancier widget.
|
||||
*/
|
||||
(function ($) {
|
||||
Drupal.behaviors.field_example_colorpicker = {
|
||||
attach: function(context) {
|
||||
$(".edit-field-example-colorpicker").live("focus", function(event) {
|
||||
var edit_field = this;
|
||||
var picker = $(this).closest('div').parent().find(".field-example-colorpicker");
|
||||
|
||||
// Hide all color pickers except this one.
|
||||
$(".field-example-colorpicker").hide();
|
||||
$(picker).show();
|
||||
$.farbtastic(picker, function(color) {
|
||||
edit_field.value = color;
|
||||
}).setColor(edit_field.value);
|
||||
});
|
||||
}
|
||||
}
|
||||
})(jQuery);
|
@@ -0,0 +1,389 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* An example field using the Field Types API.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup field_example Example: Field Types API
|
||||
* @ingroup examples
|
||||
* @{
|
||||
* Examples using Field Types API.
|
||||
*
|
||||
* This is updated from Barry Jaspan's presentation at Drupalcon Paris,
|
||||
* @link http://acquia.com/community/resources/acquia-tv/intro-field-api-module-developers Video Presentation @endlink
|
||||
*
|
||||
* Providing a field requires:
|
||||
* - Defining a field:
|
||||
* - hook_field_info()
|
||||
* - hook_field_schema()
|
||||
* - hook_field_validate()
|
||||
* - hook_field_is_empty()
|
||||
*
|
||||
* - Defining a formatter for the field (the portion that outputs the field for
|
||||
* display):
|
||||
* - hook_field_formatter_info()
|
||||
* - hook_field_formatter_view()
|
||||
*
|
||||
* - Defining a widget for the edit form:
|
||||
* - hook_field_widget_info()
|
||||
* - hook_field_widget_form()
|
||||
*
|
||||
* Our module defines the field in field_example_field_info(),
|
||||
* field_example_field_validate() and field_example_field_is_empty().
|
||||
* field_example_field_schema() is implemented in field_example.install.
|
||||
*
|
||||
* Our module sets up a formatter in field_example_field_formatter_info() and
|
||||
* field_example_field_formatter_view(). These are the API hooks that present
|
||||
* formatted and themed output to the user.
|
||||
*
|
||||
* And finally, our module defines the widget in
|
||||
* field_example_field_widget_info() and field_example_field_widget_form().
|
||||
* The widget is the form element used to receive input from the user
|
||||
* when the field is being populated.
|
||||
*
|
||||
* @see field_types
|
||||
* @see field
|
||||
*/
|
||||
|
||||
/***************************************************************
|
||||
* Field Type API hooks
|
||||
***************************************************************/
|
||||
|
||||
/**
|
||||
* Implements hook_field_info().
|
||||
*
|
||||
* Provides the description of the field.
|
||||
*/
|
||||
function field_example_field_info() {
|
||||
return array(
|
||||
// We name our field as the associative name of the array.
|
||||
'field_example_rgb' => array(
|
||||
'label' => t('Example Color RGB'),
|
||||
'description' => t('Demonstrates a field composed of an RGB color.'),
|
||||
'default_widget' => 'field_example_3text',
|
||||
'default_formatter' => 'field_example_simple_text',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_validate().
|
||||
*
|
||||
* This hook gives us a chance to validate content that's in our
|
||||
* field. We're really only interested in the $items parameter, since
|
||||
* it holds arrays representing content in the field we've defined.
|
||||
* We want to verify that the items only contain RGB hex values like
|
||||
* this: #RRGGBB. If the item validates, we do nothing. If it doesn't
|
||||
* validate, we add our own error notification to the $errors parameter.
|
||||
*
|
||||
* @see field_example_field_widget_error()
|
||||
*/
|
||||
function field_example_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
|
||||
foreach ($items as $delta => $item) {
|
||||
if (!empty($item['rgb'])) {
|
||||
if (!preg_match('@^#[0-9a-f]{6}$@', $item['rgb'])) {
|
||||
$errors[$field['field_name']][$langcode][$delta][] = array(
|
||||
'error' => 'field_example_invalid',
|
||||
'message' => t('Color must be in the HTML format #abcdef.'),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_field_is_empty().
|
||||
*
|
||||
* hook_field_is_empty() is where Drupal asks us if this field is empty.
|
||||
* Return TRUE if it does not contain data, FALSE if it does. This lets
|
||||
* the form API flag an error when required fields are empty.
|
||||
*/
|
||||
function field_example_field_is_empty($item, $field) {
|
||||
return empty($item['rgb']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_formatter_info().
|
||||
*
|
||||
* We need to tell Drupal that we have two different types of formatters
|
||||
* for this field. One will change the text color, and the other will
|
||||
* change the background color.
|
||||
*
|
||||
* @see field_example_field_formatter_view()
|
||||
*/
|
||||
function field_example_field_formatter_info() {
|
||||
return array(
|
||||
// This formatter just displays the hex value in the color indicated.
|
||||
'field_example_simple_text' => array(
|
||||
'label' => t('Simple text-based formatter'),
|
||||
'field types' => array('field_example_rgb'),
|
||||
),
|
||||
// This formatter changes the background color of the content region.
|
||||
'field_example_color_background' => array(
|
||||
'label' => t('Change the background of the output text'),
|
||||
'field types' => array('field_example_rgb'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_formatter_view().
|
||||
*
|
||||
* Two formatters are implemented.
|
||||
* - field_example_simple_text just outputs markup indicating the color that
|
||||
* was entered and uses an inline style to set the text color to that value.
|
||||
* - field_example_color_background does the same but also changes the
|
||||
* background color of div.region-content.
|
||||
*
|
||||
* @see field_example_field_formatter_info()
|
||||
*/
|
||||
function field_example_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
|
||||
$element = array();
|
||||
|
||||
switch ($display['type']) {
|
||||
// This formatter simply outputs the field as text and with a color.
|
||||
case 'field_example_simple_text':
|
||||
foreach ($items as $delta => $item) {
|
||||
$element[$delta] = array(
|
||||
// We create a render array to produce the desired markup,
|
||||
// "<p style="color: #hexcolor">The color code ... #hexcolor</p>".
|
||||
// See theme_html_tag().
|
||||
'#type' => 'html_tag',
|
||||
'#tag' => 'p',
|
||||
'#attributes' => array(
|
||||
'style' => 'color: ' . $item['rgb'],
|
||||
),
|
||||
'#value' => t('The color code in this field is @code', array('@code' => $item['rgb'])),
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
// This formatter adds css to the page changing the '.region-content' area's
|
||||
// background color. If there are many fields, the last one will win.
|
||||
case 'field_example_color_background':
|
||||
foreach ($items as $delta => $item) {
|
||||
$element[$delta] = array(
|
||||
'#type' => 'html_tag',
|
||||
'#tag' => 'p',
|
||||
'#value' => t('The content area color has been changed to @code', array('@code' => $item['rgb'])),
|
||||
'#attached' => array(
|
||||
'css' => array(
|
||||
array(
|
||||
'data' => 'div.region-content { background-color:' . $item['rgb'] . ';}',
|
||||
'type' => 'inline',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_widget_info().
|
||||
*
|
||||
* Three widgets are provided.
|
||||
* - A simple text-only widget where the user enters the '#ffffff'.
|
||||
* - A 3-textfield widget that gathers the red, green, and blue values
|
||||
* separately.
|
||||
* - A farbtastic colorpicker widget that chooses the value graphically.
|
||||
*
|
||||
* These widget types will eventually show up in hook_field_widget_form,
|
||||
* where we will have to flesh them out.
|
||||
*
|
||||
* @see field_example_field_widget_form()
|
||||
*/
|
||||
function field_example_field_widget_info() {
|
||||
return array(
|
||||
'field_example_text' => array(
|
||||
'label' => t('RGB value as #ffffff'),
|
||||
'field types' => array('field_example_rgb'),
|
||||
),
|
||||
'field_example_3text' => array(
|
||||
'label' => t('RGB text field'),
|
||||
'field types' => array('field_example_rgb'),
|
||||
),
|
||||
'field_example_colorpicker' => array(
|
||||
'label' => t('Color Picker'),
|
||||
'field types' => array('field_example_rgb'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_widget_form().
|
||||
*
|
||||
* hook_widget_form() is where Drupal tells us to create form elements for
|
||||
* our field's widget.
|
||||
*
|
||||
* We provide one of three different forms, depending on the widget type of
|
||||
* the Form API item provided.
|
||||
*
|
||||
* The 'field_example_colorpicker' and 'field_example_text' are essentially
|
||||
* the same, but field_example_colorpicker adds a javascript colorpicker
|
||||
* helper.
|
||||
*
|
||||
* field_example_3text displays three text fields, one each for red, green,
|
||||
* and blue. However, the field type defines a single text column,
|
||||
* rgb, which needs an HTML color spec. Define an element validate
|
||||
* handler that converts our r, g, and b fields into a simulated single
|
||||
* 'rgb' form element.
|
||||
*/
|
||||
function field_example_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
|
||||
$value = isset($items[$delta]['rgb']) ? $items[$delta]['rgb'] : '';
|
||||
|
||||
$widget = $element;
|
||||
$widget['#delta'] = $delta;
|
||||
|
||||
switch ($instance['widget']['type']) {
|
||||
|
||||
case 'field_example_colorpicker':
|
||||
$widget += array(
|
||||
'#suffix' => '<div class="field-example-colorpicker"></div>',
|
||||
'#attributes' => array('class' => array('edit-field-example-colorpicker')),
|
||||
'#attached' => array(
|
||||
// Add Farbtastic color picker.
|
||||
'library' => array(
|
||||
array('system', 'farbtastic'),
|
||||
),
|
||||
// Add javascript to trigger the colorpicker.
|
||||
'js' => array(drupal_get_path('module', 'field_example') . '/field_example.js'),
|
||||
),
|
||||
);
|
||||
// DELIBERATE fall-through: From here on the field_example_text and
|
||||
// field_example_colorpicker are exactly the same.
|
||||
case 'field_example_text':
|
||||
$widget += array(
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => $value,
|
||||
// Allow a slightly larger size that the field length to allow for some
|
||||
// configurations where all characters won't fit in input field.
|
||||
'#size' => 7,
|
||||
'#maxlength' => 7,
|
||||
);
|
||||
break;
|
||||
|
||||
case 'field_example_3text':
|
||||
// Convert rgb value into r, g, and b for #default_value.
|
||||
if (!empty($value)) {
|
||||
preg_match_all('@..@', substr($value, 1), $match);
|
||||
}
|
||||
else {
|
||||
$match = array(array());
|
||||
}
|
||||
|
||||
// Make this a fieldset with the three text fields.
|
||||
$widget += array(
|
||||
'#type' => 'fieldset',
|
||||
'#element_validate' => array('field_example_3text_validate'),
|
||||
|
||||
// #delta is set so that the validation function will be able
|
||||
// to access external value information which otherwise would be
|
||||
// unavailable.
|
||||
'#delta' => $delta,
|
||||
|
||||
'#attached' => array(
|
||||
'css' => array(drupal_get_path('module', 'field_example') . '/field_example.css'),
|
||||
),
|
||||
);
|
||||
|
||||
// Create a textfield for saturation values for Red, Green, and Blue.
|
||||
foreach (array('r' => t('Red'), 'g' => t('Green'), 'b' => t('Blue')) as $key => $title) {
|
||||
$widget[$key] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => $title,
|
||||
'#size' => 2,
|
||||
'#default_value' => array_shift($match[0]),
|
||||
'#attributes' => array('class' => array('rgb-entry')),
|
||||
'#description' => t('The 2-digit hexadecimal representation of @color saturation, like "a1" or "ff"', array('@color' => $title)),
|
||||
);
|
||||
// Since Form API doesn't allow a fieldset to be required, we
|
||||
// have to require each field element individually.
|
||||
if ($instance['required'] == 1) {
|
||||
$widget[$key]['#required'] = 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
$element['rgb'] = $widget;
|
||||
return $element;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validate the individual fields and then convert to RGB string.
|
||||
*/
|
||||
function field_example_3text_validate($element, &$form_state) {
|
||||
// @todo: Isn't there a better way to find out which element?
|
||||
$delta = $element['#delta'];
|
||||
$field = $form_state['field'][$element['#field_name']][$element['#language']]['field'];
|
||||
$field_name = $field['field_name'];
|
||||
if (isset($form_state['values'][$field_name][$element['#language']][$delta]['rgb'])) {
|
||||
$values = $form_state['values'][$field_name][$element['#language']][$delta]['rgb'];
|
||||
foreach (array('r', 'g', 'b') as $colorfield) {
|
||||
$colorfield_value = hexdec($values[$colorfield]);
|
||||
// If they left any empty, we'll set the value empty and quit.
|
||||
if (strlen($values[$colorfield]) == 0) {
|
||||
form_set_value($element, '', $form_state);
|
||||
return;
|
||||
}
|
||||
// If they gave us anything that's not hex, reject it.
|
||||
if ((strlen($values[$colorfield]) != 2) || $colorfield_value < 0 || $colorfield_value > 255) {
|
||||
form_error($element[$colorfield], t("Saturation value must be a 2-digit hexadecimal value between 00 and ff."));
|
||||
}
|
||||
}
|
||||
|
||||
$value = sprintf('#%02s%02s%02s', $values['r'], $values['g'], $values['b']);
|
||||
form_set_value($element, $value, $form_state);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_widget_error().
|
||||
*
|
||||
* hook_field_widget_error() lets us figure out what to do with errors
|
||||
* we might have generated in hook_field_validate(). Generally, we'll just
|
||||
* call form_error().
|
||||
*
|
||||
* @see field_example_field_validate()
|
||||
* @see form_error()
|
||||
*/
|
||||
function field_example_field_widget_error($element, $error, $form, &$form_state) {
|
||||
switch ($error['error']) {
|
||||
case 'field_example_invalid':
|
||||
form_error($element, $error['message']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*
|
||||
* Provides a simple user interface that tells the developer where to go.
|
||||
*/
|
||||
function field_example_menu() {
|
||||
$items['examples/field_example'] = array(
|
||||
'title' => 'Field Example',
|
||||
'page callback' => '_field_example_page',
|
||||
'access callback' => TRUE,
|
||||
);
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple page to explain to the developer what to do.
|
||||
*/
|
||||
function _field_example_page() {
|
||||
return t("The Field Example provides a field composed of an HTML RGB value, like #ff00ff. To use it, add the field to a content type.");
|
||||
}
|
||||
/**
|
||||
* @} End of "defgroup field_example".
|
||||
*/
|
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Tests for Field Example.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Functional tests for the Field Example module.
|
||||
*
|
||||
* @ingroup field_example
|
||||
*/
|
||||
class FieldExampleTest extends DrupalWebTestCase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Field Example',
|
||||
'description' => 'Create a content type with example_field_rgb fields, create a node, check for correct values.',
|
||||
'group' => 'Examples',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setUp() {
|
||||
// Enable the email_example module.
|
||||
parent::setUp(array('field_ui', 'field_example'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test basic functionality of the example field.
|
||||
*
|
||||
* - Creates a content type.
|
||||
* - Adds a single-valued field_example_rgb to it.
|
||||
* - Adds a multivalued field_example_rgb to it.
|
||||
* - Creates a node of the new type.
|
||||
* - Populates the single-valued field.
|
||||
* - Populates the multivalued field with two items.
|
||||
* - Tests the result.
|
||||
*/
|
||||
public function testExampleFieldBasic() {
|
||||
$content_type_machine = strtolower($this->randomName(10));
|
||||
$title = $this->randomName(20);
|
||||
|
||||
// Create and login user.
|
||||
$account = $this->drupalCreateUser(array('administer content types', 'administer fields'));
|
||||
$this->drupalLogin($account);
|
||||
|
||||
$this->drupalGet('admin/structure/types');
|
||||
|
||||
// Create the content type.
|
||||
$this->clickLink(t('Add content type'));
|
||||
|
||||
$edit = array(
|
||||
'name' => $content_type_machine,
|
||||
'type' => $content_type_machine,
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save and add fields'));
|
||||
$this->assertText(t('The content type @name has been added.', array('@name' => $content_type_machine)));
|
||||
|
||||
$single_text_field = strtolower($this->randomName(10));
|
||||
$single_colorpicker_field = strtolower($this->randomName(10));
|
||||
$single_3text_field = strtolower($this->randomName(10));
|
||||
$multivalue_3text_field = strtolower($this->randomName(10));
|
||||
|
||||
// Description of fields to be created;
|
||||
$fields[$single_text_field] = array(
|
||||
'widget' => 'field_example_text',
|
||||
'cardinality' => '1',
|
||||
);
|
||||
$fields[$single_colorpicker_field] = array(
|
||||
'widget' => 'field_example_colorpicker',
|
||||
'cardinality' => 1,
|
||||
);
|
||||
$fields[$single_3text_field] = array(
|
||||
'widget' => 'field_example_3text',
|
||||
'cardinality' => 1,
|
||||
);
|
||||
$fields[$multivalue_3text_field] = array(
|
||||
'widget' => 'field_example_3text',
|
||||
'cardinality' => -1,
|
||||
);
|
||||
|
||||
foreach ($fields as $fieldname => $details) {
|
||||
$this->createField($fieldname, $details['widget'], $details['cardinality']);
|
||||
}
|
||||
|
||||
// Somehow clicking "save" isn't enough, and we have to do a
|
||||
// node_types_rebuild().
|
||||
node_types_rebuild();
|
||||
menu_rebuild();
|
||||
$type_exists = db_query('SELECT 1 FROM {node_type} WHERE type = :type', array(':type' => $content_type_machine))->fetchField();
|
||||
$this->assertTrue($type_exists, 'The new content type has been created in the database.');
|
||||
|
||||
$permission = 'create ' . $content_type_machine . ' content';
|
||||
// Reset the permissions cache.
|
||||
$this->checkPermissions(array($permission), TRUE);
|
||||
|
||||
// Now that we have a new content type, create a user that has privileges
|
||||
// on the content type.
|
||||
$account = $this->drupalCreateUser(array($permission));
|
||||
$this->drupalLogin($account);
|
||||
|
||||
$this->drupalGet('node/add/' . $content_type_machine);
|
||||
|
||||
// Add a node.
|
||||
$edit = array(
|
||||
'title' => $title,
|
||||
'field_' . $single_text_field . '[und][0][rgb]' => '#000001',
|
||||
'field_' . $single_colorpicker_field . '[und][0][rgb]' => '#000002',
|
||||
|
||||
'field_' . $single_3text_field . '[und][0][rgb][r]' => '00',
|
||||
'field_' . $single_3text_field . '[und][0][rgb][g]' => '00',
|
||||
'field_' . $single_3text_field . '[und][0][rgb][b]' => '03',
|
||||
|
||||
'field_' . $multivalue_3text_field . '[und][0][rgb][r]' => '00',
|
||||
'field_' . $multivalue_3text_field . '[und][0][rgb][g]' => '00',
|
||||
'field_' . $multivalue_3text_field . '[und][0][rgb][b]' => '04',
|
||||
|
||||
);
|
||||
// We want to add a 2nd item to the multivalue field, so hit "add another".
|
||||
$this->drupalPost(NULL, $edit, t('Add another item'));
|
||||
|
||||
$edit = array(
|
||||
'field_' . $multivalue_3text_field . '[und][1][rgb][r]' => '00',
|
||||
'field_' . $multivalue_3text_field . '[und][1][rgb][g]' => '00',
|
||||
'field_' . $multivalue_3text_field . '[und][1][rgb][b]' => '05',
|
||||
);
|
||||
// Now we can fill in the second item in the multivalue field and save.
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
$this->assertText(t('@content_type_machine @title has been created', array('@content_type_machine' => $content_type_machine, '@title' => $title)));
|
||||
|
||||
$output_strings = $this->xpath("//div[contains(@class,'field-type-field-example-rgb')]/div/div/p/text()");
|
||||
|
||||
$this->assertEqual((string) $output_strings[0], "The color code in this field is #000001");
|
||||
$this->assertEqual((string) $output_strings[1], "The color code in this field is #000002");
|
||||
$this->assertEqual((string) $output_strings[2], "The color code in this field is #000003");
|
||||
$this->assertEqual((string) $output_strings[3], "The color code in this field is #000004");
|
||||
$this->assertEqual((string) $output_strings[4], "The color code in this field is #000005");
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility function to create fields on a content type.
|
||||
*
|
||||
* @param string $field_name
|
||||
* Name of the field, like field_something
|
||||
* @param string $widget_type
|
||||
* Widget type, like field_example_3text
|
||||
* @param int $cardinality
|
||||
* Cardinality
|
||||
*/
|
||||
protected function createField($field_name, $widget_type, $cardinality) {
|
||||
// Add a singleton field_example_text field.
|
||||
$edit = array(
|
||||
'fields[_add_new_field][label]' => $field_name,
|
||||
'fields[_add_new_field][field_name]' => $field_name,
|
||||
'fields[_add_new_field][type]' => 'field_example_rgb',
|
||||
'fields[_add_new_field][widget_type]' => $widget_type,
|
||||
|
||||
);
|
||||
$this->drupalPost(NULL, $edit, t('Save'));
|
||||
|
||||
// There are no settings for this, so just press the button.
|
||||
$this->drupalPost(NULL, array(), t('Save field settings'));
|
||||
|
||||
$edit = array('field[cardinality]' => (string) $cardinality);
|
||||
|
||||
// Using all the default settings, so press the button.
|
||||
$this->drupalPost(NULL, $edit, t('Save settings'));
|
||||
debug(
|
||||
t('Saved settings for field %field_name with widget %widget_type and cardinality %cardinality',
|
||||
array(
|
||||
'%field_name' => $field_name,
|
||||
'%widget_type' => $widget_type,
|
||||
'%cardinality' => $cardinality,
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertText(t('Saved @name configuration.', array('@name' => $field_name)));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user