Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • develop
  • issue-424
  • master
  • master-no-logins
  • svn-staging
  • svn-testing
  • svn-trunk
  • topics/add-contribution-info
  • 2010-11-11
  • 2010-12-15
  • 2011-01-11
  • 2011-01-18
  • 2011-01-26
  • 2011-02-10
  • 2011-02-23
  • 2011-03-09
  • 2011-03-15
  • 2011-03-30
  • 2011-04-05
  • 2011-05-03
  • 2011-05-12
  • 2011-06-16
  • 2011-06-21
  • 2011-06-23
  • 2011-06-29
  • 2011-06-30
  • 2011-07-11
  • 2011-07-18
  • 2011-07-20
  • 2011-07-21
  • 2011-07-28
  • 2011-08-03
  • 2011-08-05
  • 2011-08-15
  • 2011-08-17
  • 2011-08-29
  • 2011-08-30
  • 2011-09-19
  • 2011-10-03
  • 2011-10-06
  • 2011-10-27
  • 2011-11-01
  • 2011-11-08
  • 2011-11-08.2
  • 2011-11-14
  • 2011-11-17
  • 2011-12-05
  • 2011-12-16
  • 2012-01-12
  • 2012-01-13
  • 2012-02-07
  • 2012-03-01
  • 2012-04-02
  • 2012-04-03
  • 2012-04-18
  • 20120207
  • 7.1
  • 7.10
  • 7.11
  • 7.12
  • 7.13
  • 7.14
  • 7.15
  • 7.16
  • 7.16.1
  • 7.17
  • 7.18
  • 7.19
  • 7.2
  • 7.3
  • 7.3.1
  • 7.4
  • 7.5
  • 7.5.1
  • 7.6
  • 7.6.1
  • 7.7
  • 7.7.1
  • 7.7.2
  • 7.7.3
  • 7.8
  • 7.9
82 results

Target

Select target project
  • rklusman2/UNL-CMS
  • yzha1/UNL-CMS
  • pear/UNL-CMS
  • bbieber2/UNL-CMS
  • tsteiner2/UNL-CMS
  • erasmussen2/UNL-CMS
  • UNL-Information-Services/UNL-CMS
7 results
Select Git revision
Loading items
Show changes
<?php <?php
// $Id: options.module,v 1.27 2010/08/17 21:48:39 dries Exp $
/** /**
* @file * @file
...@@ -61,6 +60,7 @@ function options_field_widget_info() { ...@@ -61,6 +60,7 @@ function options_field_widget_info() {
'behaviors' => array( 'behaviors' => array(
'multiple values' => FIELD_BEHAVIOR_CUSTOM, 'multiple values' => FIELD_BEHAVIOR_CUSTOM,
), ),
'settings' => array('display_label' => 0),
), ),
); );
} }
...@@ -79,8 +79,11 @@ function options_field_widget_form(&$form, &$form_state, $field, $instance, $lan ...@@ -79,8 +79,11 @@ function options_field_widget_form(&$form, &$form_state, $field, $instance, $lan
$has_value = isset($items[0][$value_key]); $has_value = isset($items[0][$value_key]);
$properties = _options_properties($type, $multiple, $required, $has_value); $properties = _options_properties($type, $multiple, $required, $has_value);
$entity_type = $element['#entity_type'];
$entity = $element['#entity'];
// Prepare the list of options. // Prepare the list of options.
$options = _options_get_options($field, $instance, $properties); $options = _options_get_options($field, $instance, $properties, $entity_type, $entity);
// Put current field values in shape. // Put current field values in shape.
$default_value = _options_storage_to_form($items, $options, $value_key, $properties); $default_value = _options_storage_to_form($items, $options, $value_key, $properties);
...@@ -102,10 +105,18 @@ function options_field_widget_form(&$form, &$form_state, $field, $instance, $lan ...@@ -102,10 +105,18 @@ function options_field_widget_form(&$form, &$form_state, $field, $instance, $lan
reset($options); reset($options);
$default_value = array(key($options)); $default_value = array(key($options));
} }
// If this is a single-value field, take the first default value, or
// default to NULL so that the form element is properly recognized as
// not having a default value.
if (!$multiple) {
$default_value = $default_value ? reset($default_value) : NULL;
}
$element += array( $element += array(
'#type' => $multiple ? 'checkboxes' : 'radios', '#type' => $multiple ? 'checkboxes' : 'radios',
// Radio buttons need a scalar value. // Radio buttons need a scalar value.
'#default_value' => $multiple ? $default_value : reset($default_value), '#default_value' => $default_value,
'#options' => $options, '#options' => $options,
); );
break; break;
...@@ -122,6 +133,10 @@ function options_field_widget_form(&$form, &$form_state, $field, $instance, $lan ...@@ -122,6 +133,10 @@ function options_field_widget_form(&$form, &$form_state, $field, $instance, $lan
); );
// Override the title from the incoming $element. // Override the title from the incoming $element.
$element['#title'] = isset($options[$on_value]) ? $options[$on_value] : ''; $element['#title'] = isset($options[$on_value]) ? $options[$on_value] : '';
if ($instance['widget']['settings']['display_label']) {
$element['#title'] = $instance['label'];
}
break; break;
} }
...@@ -134,6 +149,22 @@ function options_field_widget_form(&$form, &$form_state, $field, $instance, $lan ...@@ -134,6 +149,22 @@ function options_field_widget_form(&$form, &$form_state, $field, $instance, $lan
return $element; return $element;
} }
/**
* Implements hook_field_widget_settings_form().
*/
function options_field_widget_settings_form($field, $instance) {
$form = array();
if ($instance['widget']['type'] == 'options_onoff') {
$form['display_label'] = array(
'#type' => 'checkbox',
'#title' => t('Use field label instead of the "On value" as label'),
'#default_value' => $instance['widget']['settings']['display_label'],
'#weight' => -1,
);
}
return $form;
}
/** /**
* Form element validation handler for options element. * Form element validation handler for options element.
*/ */
...@@ -152,7 +183,6 @@ function options_field_widget_validate($element, &$form_state) { ...@@ -152,7 +183,6 @@ function options_field_widget_validate($element, &$form_state) {
*/ */
function _options_properties($type, $multiple, $required, $has_value) { function _options_properties($type, $multiple, $required, $has_value) {
$base = array( $base = array(
'zero_placeholder' => FALSE,
'filter_xss' => FALSE, 'filter_xss' => FALSE,
'strip_tags' => FALSE, 'strip_tags' => FALSE,
'empty_option' => FALSE, 'empty_option' => FALSE,
...@@ -190,9 +220,6 @@ function _options_properties($type, $multiple, $required, $has_value) { ...@@ -190,9 +220,6 @@ function _options_properties($type, $multiple, $required, $has_value) {
case 'buttons': case 'buttons':
$properties = array( $properties = array(
'filter_xss' => TRUE, 'filter_xss' => TRUE,
// Form API 'checkboxes' do not suport 0 as an option, so we replace it with
// a placeholder within the form workflow.
'zero_placeholder' => $multiple,
); );
// Add a 'none' option for non-required radio buttons. // Add a 'none' option for non-required radio buttons.
if (!$required && !$multiple) { if (!$required && !$multiple) {
...@@ -213,9 +240,9 @@ function _options_properties($type, $multiple, $required, $has_value) { ...@@ -213,9 +240,9 @@ function _options_properties($type, $multiple, $required, $has_value) {
/** /**
* Collects the options for a field. * Collects the options for a field.
*/ */
function _options_get_options($field, $instance, $properties) { function _options_get_options($field, $instance, $properties, $entity_type, $entity) {
// Get the list of options. // Get the list of options.
$options = (array) module_invoke($field['module'], 'options_list', $field); $options = (array) module_invoke($field['module'], 'options_list', $field, $instance, $entity_type, $entity);
// Sanitize the options. // Sanitize the options.
_options_prepare_options($options, $properties); _options_prepare_options($options, $properties);
...@@ -238,18 +265,6 @@ function _options_get_options($field, $instance, $properties) { ...@@ -238,18 +265,6 @@ function _options_get_options($field, $instance, $properties) {
* The function is recursive to support optgroups. * The function is recursive to support optgroups.
*/ */
function _options_prepare_options(&$options, $properties) { function _options_prepare_options(&$options, $properties) {
// Substitute the '_0' placeholder.
if ($properties['zero_placeholder']) {
$values = array_keys($options);
$labels = array_values($options);
// Use a strict comparison, because 0 == 'any string'.
$index = array_search(0, $values, TRUE);
if ($index !== FALSE && !is_array($options[$index])) {
$values[$index] = '_0';
$options = array_combine($values, $labels);
}
}
foreach ($options as $value => $label) { foreach ($options as $value => $label) {
// Recurse for optgroups. // Recurse for optgroups.
if (is_array($label)) { if (is_array($label)) {
...@@ -273,14 +288,6 @@ function _options_storage_to_form($items, $options, $column, $properties) { ...@@ -273,14 +288,6 @@ function _options_storage_to_form($items, $options, $column, $properties) {
$items_transposed = options_array_transpose($items); $items_transposed = options_array_transpose($items);
$values = (isset($items_transposed[$column]) && is_array($items_transposed[$column])) ? $items_transposed[$column] : array(); $values = (isset($items_transposed[$column]) && is_array($items_transposed[$column])) ? $items_transposed[$column] : array();
// Substitute the '_0' placeholder.
if ($properties['zero_placeholder']) {
$index = array_search('0', $values);
if ($index !== FALSE) {
$values[$index] = '_0';
}
}
// Discard values that are not in the current list of options. Flatten the // Discard values that are not in the current list of options. Flatten the
// array if needed. // array if needed.
if ($properties['optgroups']) { if ($properties['optgroups']) {
...@@ -302,14 +309,6 @@ function _options_form_to_storage($element) { ...@@ -302,14 +309,6 @@ function _options_form_to_storage($element) {
$values = array($values[0] ? $element['#on_value'] : $element['#off_value']); $values = array($values[0] ? $element['#on_value'] : $element['#off_value']);
} }
// Substitute the '_0' placeholder.
if ($properties['zero_placeholder']) {
$index = array_search('_0', $values);
if ($index !== FALSE) {
$values[$index] = 0;
}
}
// Filter out the 'none' option. Use a strict comparison, because // Filter out the 'none' option. Use a strict comparison, because
// 0 == 'any string'. // 0 == 'any string'.
if ($properties['empty_option']) { if ($properties['empty_option']) {
......
<?php <?php
// $Id: options.test,v 1.17 2010/09/24 00:37:42 dries Exp $
/**
* @file
* Tests for options.module.
*/
class OptionsWidgetsTestCase extends FieldTestCase { class OptionsWidgetsTestCase extends FieldTestCase {
public static function getInfo() { public static function getInfo() {
...@@ -16,11 +20,11 @@ class OptionsWidgetsTestCase extends FieldTestCase { ...@@ -16,11 +20,11 @@ class OptionsWidgetsTestCase extends FieldTestCase {
// Field with cardinality 1. // Field with cardinality 1.
$this->card_1 = array( $this->card_1 = array(
'field_name' => 'card_1', 'field_name' => 'card_1',
'type' => 'list', 'type' => 'list_integer',
'cardinality' => 1, 'cardinality' => 1,
'settings' => array( 'settings' => array(
// Make sure that 0 works as an option. // Make sure that 0 works as an option.
'allowed_values' => "0|Zero\n1|One\n2|Some <script>dangerous</script> & unescaped <strong>markup</strong>\n", 'allowed_values' => array(0 => 'Zero', 1 => 'One', 2 => 'Some <script>dangerous</script> & unescaped <strong>markup</strong>'),
), ),
); );
$this->card_1 = field_create_field($this->card_1); $this->card_1 = field_create_field($this->card_1);
...@@ -28,11 +32,11 @@ class OptionsWidgetsTestCase extends FieldTestCase { ...@@ -28,11 +32,11 @@ class OptionsWidgetsTestCase extends FieldTestCase {
// Field with cardinality 2. // Field with cardinality 2.
$this->card_2 = array( $this->card_2 = array(
'field_name' => 'card_2', 'field_name' => 'card_2',
'type' => 'list', 'type' => 'list_integer',
'cardinality' => 2, 'cardinality' => 2,
'settings' => array( 'settings' => array(
// Make sure that 0 works as an option. // Make sure that 0 works as an option.
'allowed_values' => "0|Zero\n1|One\n2|Some <script>dangerous</script> & unescaped <strong>markup</strong>\n", 'allowed_values' => array(0 => 'Zero', 1 => 'One', 2 => 'Some <script>dangerous</script> & unescaped <strong>markup</strong>'),
), ),
); );
$this->card_2 = field_create_field($this->card_2); $this->card_2 = field_create_field($this->card_2);
...@@ -44,7 +48,7 @@ class OptionsWidgetsTestCase extends FieldTestCase { ...@@ -44,7 +48,7 @@ class OptionsWidgetsTestCase extends FieldTestCase {
'cardinality' => 1, 'cardinality' => 1,
'settings' => array( 'settings' => array(
// Make sure that 0 works as a 'on' value'. // Make sure that 0 works as a 'on' value'.
'allowed_values' => "1|No\n0|Some <script>dangerous</script> & unescaped <strong>markup</strong>\n", 'allowed_values' => array(1 => 'Zero', 0 => 'Some <script>dangerous</script> & unescaped <strong>markup</strong>'),
), ),
); );
$this->bool = field_create_field($this->bool); $this->bool = field_create_field($this->bool);
...@@ -100,7 +104,7 @@ class OptionsWidgetsTestCase extends FieldTestCase { ...@@ -100,7 +104,7 @@ class OptionsWidgetsTestCase extends FieldTestCase {
$this->assertFieldValues($entity_init, 'card_1', $langcode, array()); $this->assertFieldValues($entity_init, 'card_1', $langcode, array());
// Check that required radios with one option is auto-selected. // Check that required radios with one option is auto-selected.
$this->card_1['settings']['allowed_values'] = '99|Only allowed value'; $this->card_1['settings']['allowed_values'] = array(99 => 'Only allowed value');
field_update_field($this->card_1); field_update_field($this->card_1);
$instance['required'] = TRUE; $instance['required'] = TRUE;
field_update_instance($instance); field_update_instance($instance);
...@@ -112,9 +116,6 @@ class OptionsWidgetsTestCase extends FieldTestCase { ...@@ -112,9 +116,6 @@ class OptionsWidgetsTestCase extends FieldTestCase {
* Tests the 'options_buttons' widget (multiple select). * Tests the 'options_buttons' widget (multiple select).
*/ */
function testCheckBoxes() { function testCheckBoxes() {
// Checkboxes do not support '0' as an option, the widget internally
// replaces it with '_0'.
// Create an instance of the 'multiple values' field. // Create an instance of the 'multiple values' field.
$instance = array( $instance = array(
'field_name' => $this->card_2['field_name'], 'field_name' => $this->card_2['field_name'],
...@@ -142,7 +143,7 @@ class OptionsWidgetsTestCase extends FieldTestCase { ...@@ -142,7 +143,7 @@ class OptionsWidgetsTestCase extends FieldTestCase {
// Submit form: select first and third options. // Submit form: select first and third options.
$edit = array( $edit = array(
"card_2[$langcode][_0]" => TRUE, "card_2[$langcode][0]" => TRUE,
"card_2[$langcode][1]" => FALSE, "card_2[$langcode][1]" => FALSE,
"card_2[$langcode][2]" => TRUE, "card_2[$langcode][2]" => TRUE,
); );
...@@ -157,7 +158,7 @@ class OptionsWidgetsTestCase extends FieldTestCase { ...@@ -157,7 +158,7 @@ class OptionsWidgetsTestCase extends FieldTestCase {
// Submit form: select only first option. // Submit form: select only first option.
$edit = array( $edit = array(
"card_2[$langcode][_0]" => TRUE, "card_2[$langcode][0]" => TRUE,
"card_2[$langcode][1]" => FALSE, "card_2[$langcode][1]" => FALSE,
"card_2[$langcode][2]" => FALSE, "card_2[$langcode][2]" => FALSE,
); );
...@@ -172,7 +173,7 @@ class OptionsWidgetsTestCase extends FieldTestCase { ...@@ -172,7 +173,7 @@ class OptionsWidgetsTestCase extends FieldTestCase {
// Submit form: select the three options while the field accepts only 2. // Submit form: select the three options while the field accepts only 2.
$edit = array( $edit = array(
"card_2[$langcode][_0]" => TRUE, "card_2[$langcode][0]" => TRUE,
"card_2[$langcode][1]" => TRUE, "card_2[$langcode][1]" => TRUE,
"card_2[$langcode][2]" => TRUE, "card_2[$langcode][2]" => TRUE,
); );
...@@ -181,7 +182,7 @@ class OptionsWidgetsTestCase extends FieldTestCase { ...@@ -181,7 +182,7 @@ class OptionsWidgetsTestCase extends FieldTestCase {
// Submit form: uncheck all options. // Submit form: uncheck all options.
$edit = array( $edit = array(
"card_2[$langcode][_0]" => FALSE, "card_2[$langcode][0]" => FALSE,
"card_2[$langcode][1]" => FALSE, "card_2[$langcode][1]" => FALSE,
"card_2[$langcode][2]" => FALSE, "card_2[$langcode][2]" => FALSE,
); );
...@@ -190,7 +191,7 @@ class OptionsWidgetsTestCase extends FieldTestCase { ...@@ -190,7 +191,7 @@ class OptionsWidgetsTestCase extends FieldTestCase {
$this->assertFieldValues($entity_init, 'card_2', $langcode, array()); $this->assertFieldValues($entity_init, 'card_2', $langcode, array());
// Required checkbox with one option is auto-selected. // Required checkbox with one option is auto-selected.
$this->card_2['settings']['allowed_values'] = '99|Only allowed value'; $this->card_2['settings']['allowed_values'] = array(99 => 'Only allowed value');
field_update_field($this->card_2); field_update_field($this->card_2);
$instance['required'] = TRUE; $instance['required'] = TRUE;
field_update_instance($instance); field_update_instance($instance);
...@@ -266,7 +267,7 @@ class OptionsWidgetsTestCase extends FieldTestCase { ...@@ -266,7 +267,7 @@ class OptionsWidgetsTestCase extends FieldTestCase {
// Test optgroups. // Test optgroups.
$this->card_1['settings']['allowed_values'] = NULL; $this->card_1['settings']['allowed_values'] = array();
$this->card_1['settings']['allowed_values_function'] = 'list_test_allowed_values_callback'; $this->card_1['settings']['allowed_values_function'] = 'list_test_allowed_values_callback';
field_update_field($this->card_1); field_update_field($this->card_1);
...@@ -381,7 +382,7 @@ class OptionsWidgetsTestCase extends FieldTestCase { ...@@ -381,7 +382,7 @@ class OptionsWidgetsTestCase extends FieldTestCase {
// Test optgroups. // Test optgroups.
// Use a callback function defining optgroups. // Use a callback function defining optgroups.
$this->card_2['settings']['allowed_values'] = NULL; $this->card_2['settings']['allowed_values'] = array();
$this->card_2['settings']['allowed_values_function'] = 'list_test_allowed_values_callback'; $this->card_2['settings']['allowed_values_function'] = 'list_test_allowed_values_callback';
field_update_field($this->card_2); field_update_field($this->card_2);
$instance['required'] = FALSE; $instance['required'] = FALSE;
...@@ -456,6 +457,97 @@ class OptionsWidgetsTestCase extends FieldTestCase { ...@@ -456,6 +457,97 @@ class OptionsWidgetsTestCase extends FieldTestCase {
// Display form: with 'off' value, option is unchecked. // Display form: with 'off' value, option is unchecked.
$this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit'); $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit');
$this->assertNoFieldChecked("edit-bool-$langcode"); $this->assertNoFieldChecked("edit-bool-$langcode");
// Create admin user.
$admin_user = $this->drupalCreateUser(array('access content', 'administer content types', 'administer taxonomy'));
$this->drupalLogin($admin_user);
// Create a test field instance.
$fieldUpdate = $this->bool;
$fieldUpdate['settings']['allowed_values'] = array(0 => 0, 1 => 'MyOnValue');
field_update_field($fieldUpdate);
$instance = array(
'field_name' => $this->bool['field_name'],
'entity_type' => 'node',
'bundle' => 'page',
'widget' => array(
'type' => 'options_onoff',
'module' => 'options',
),
);
field_create_instance($instance);
// Go to the edit page and check if the default settings works as expected
$fieldEditUrl = 'admin/structure/types/manage/page/fields/bool';
$this->drupalGet($fieldEditUrl);
$this->assertText(
'Use field label instead of the "On value" as label ',
t('Display setting checkbox available.')
);
$this->assertFieldByXPath(
'*//label[@for="edit-' . $this->bool['field_name'] . '-und" and text()="MyOnValue "]',
TRUE,
t('Default case shows "On value"')
);
// Enable setting
$edit = array('instance[widget][settings][display_label]' => 1);
// Save the new Settings
$this->drupalPost($fieldEditUrl, $edit, t('Save settings'));
// Go again to the edit page and check if the setting
// is stored and has the expected effect
$this->drupalGet($fieldEditUrl);
$this->assertText(
'Use field label instead of the "On value" as label ',
t('Display setting checkbox is available')
);
$this->assertFieldChecked(
'edit-instance-widget-settings-display-label',
t('Display settings checkbox checked')
);
$this->assertFieldByXPath(
'*//label[@for="edit-' . $this->bool['field_name'] . '-und" and text()="' . $this->bool['field_name'] . ' "]',
TRUE,
t('Display label changes label of the checkbox')
);
}
} }
/**
* Test an options select on a list field with a dynamic allowed values function.
*/
class OptionsSelectDynamicValuesTestCase extends ListDynamicValuesTestCase {
public static function getInfo() {
return array(
'name' => 'Options select dynamic values',
'description' => 'Test an options select on a list field with a dynamic allowed values function.',
'group' => 'Field types',
);
} }
/**
* Tests the 'options_select' widget (single select).
*/
function testSelectListDynamic() {
// Create an entity.
$this->entity->is_new = TRUE;
field_test_entity_save($this->entity);
// Create a web user.
$web_user = $this->drupalCreateUser(array('access field_test content', 'administer field_test content'));
$this->drupalLogin($web_user);
// Display form.
$this->drupalGet('test-entity/manage/' . $this->entity->ftid . '/edit');
$options = $this->xpath('//select[@id="edit-test-list-und"]/option');
$this->assertEqual(count($options), count($this->test) + 1);
foreach ($options as $option) {
$value = (string) $option['value'];
if ($value != '_none') {
$this->assertTrue(array_search($value, $this->test));
}
}
}
}
; $Id: text.info,v 1.8 2010/08/16 20:57:22 dries Exp $
name = Text name = Text
description = Defines simple text field types. description = Defines simple text field types.
package = Core package = Core
version = VERSION version = VERSION
core = 7.x core = 7.x
dependencies[] = field dependencies[] = field
files[] = text.module
files[] = text.test files[] = text.test
required = TRUE required = TRUE
; Information added by drupal.org packaging script on 2010-10-23 ; Information added by drupal.org packaging script on 2013-04-03
version = "7.0-beta2" version = "7.22"
project = "drupal" project = "drupal"
datestamp = "1287812130" datestamp = "1365027012"
<?php <?php
// $Id: text.install,v 1.4 2010/10/20 15:57:42 webchick Exp $
/** /**
* @file * @file
...@@ -67,19 +66,6 @@ function text_field_schema($field) { ...@@ -67,19 +66,6 @@ function text_field_schema($field) {
); );
} }
/**
* Implements hook_update_dependencies().
*/
function text_update_dependencies() {
// Ensure that format columns are only changed after Filter module has changed
// the primary records.
$dependencies['text'][7000] = array(
'filter' => 7010,
);
return $dependencies;
}
/** /**
* Change text field 'format' columns into varchar. * Change text field 'format' columns into varchar.
*/ */
...@@ -93,7 +79,7 @@ function text_update_7000() { ...@@ -93,7 +79,7 @@ function text_update_7000() {
'module' => 'text', 'module' => 'text',
'storage_type' => 'field_sql_storage', 'storage_type' => 'field_sql_storage',
)); ));
foreach ($fields as $field_name => $field) { foreach ($fields as $field) {
if ($field['deleted']) { if ($field['deleted']) {
$table = "field_deleted_data_{$field['id']}"; $table = "field_deleted_data_{$field['id']}";
$revision_table = "field_deleted_revision_{$field['id']}"; $revision_table = "field_deleted_revision_{$field['id']}";
......
// $Id: text.js,v 1.4 2010/06/12 08:18:59 webchick Exp $
(function ($) { (function ($) {
...@@ -38,7 +37,7 @@ Drupal.behaviors.textSummary = { ...@@ -38,7 +37,7 @@ Drupal.behaviors.textSummary = {
).appendTo($summaryLabel); ).appendTo($summaryLabel);
// If no summary is set, hide the summary field. // If no summary is set, hide the summary field.
if ($(this).val() == '') { if ($(this).find('.text-summary').val() == '') {
$link.click(); $link.click();
} }
return; return;
......
<?php <?php
// $Id: text.module,v 1.66 2010/10/22 00:42:42 dries Exp $
/** /**
* @file * @file
...@@ -72,7 +71,7 @@ function text_field_settings_form($field, $instance, $has_data) { ...@@ -72,7 +71,7 @@ function text_field_settings_form($field, $instance, $has_data) {
'#default_value' => $settings['max_length'], '#default_value' => $settings['max_length'],
'#required' => TRUE, '#required' => TRUE,
'#description' => t('The maximum length of the field in characters.'), '#description' => t('The maximum length of the field in characters.'),
'#element_validate' => array('_element_validate_integer_positive'), '#element_validate' => array('element_validate_integer_positive'),
// @todo: If $has_data, add a validate handler that only allows // @todo: If $has_data, add a validate handler that only allows
// max_length to increase. // max_length to increase.
'#disabled' => $has_data, '#disabled' => $has_data,
...@@ -170,8 +169,8 @@ function text_field_load($entity_type, $entities, $field, $instances, $langcode, ...@@ -170,8 +169,8 @@ function text_field_load($entity_type, $entities, $field, $instances, $langcode,
* Implements hook_field_is_empty(). * Implements hook_field_is_empty().
*/ */
function text_field_is_empty($item, $field) { function text_field_is_empty($item, $field) {
if (empty($item['value']) && (string) $item['value'] !== '0') { if (!isset($item['value']) || $item['value'] === '') {
return TRUE; return !isset($item['summary']) || $item['summary'] === '';
} }
return FALSE; return FALSE;
} }
...@@ -228,7 +227,7 @@ function text_field_formatter_settings_form($field, $instance, $view_mode, $form ...@@ -228,7 +227,7 @@ function text_field_formatter_settings_form($field, $instance, $view_mode, $form
'#type' => 'textfield', '#type' => 'textfield',
'#size' => 10, '#size' => 10,
'#default_value' => $settings['trim_length'], '#default_value' => $settings['trim_length'],
'#element_validate' => array('_element_validate_integer_positive'), '#element_validate' => array('element_validate_integer_positive'),
'#required' => TRUE, '#required' => TRUE,
); );
} }
...@@ -285,7 +284,9 @@ function text_field_formatter_view($entity_type, $entity, $field, $instance, $la ...@@ -285,7 +284,9 @@ function text_field_formatter_view($entity_type, $entity, $field, $instance, $la
case 'text_plain': case 'text_plain':
foreach ($items as $delta => $item) { foreach ($items as $delta => $item) {
$element[$delta] = array('#markup' => strip_tags($item['value'])); // The text value has no text format assigned to it, so the user input
// should equal the output, including newlines.
$element[$delta] = array('#markup' => nl2br(check_plain($item['value'])));
} }
break; break;
} }
...@@ -317,7 +318,12 @@ function _text_sanitize($instance, $langcode, $item, $column) { ...@@ -317,7 +318,12 @@ function _text_sanitize($instance, $langcode, $item, $column) {
if (isset($item["safe_$column"])) { if (isset($item["safe_$column"])) {
return $item["safe_$column"]; return $item["safe_$column"];
} }
return $instance['settings']['text_processing'] ? check_markup($item[$column], $item['format'], $langcode) : check_plain($item[$column]); if ($instance['settings']['text_processing']) {
return check_markup($item[$column], $item['format'], $langcode);
}
// Escape all HTML and retain newlines.
// @see text_field_formatter_view()
return nl2br(check_plain($item[$column]));
} }
/** /**
...@@ -481,7 +487,7 @@ function text_field_widget_settings_form($field, $instance) { ...@@ -481,7 +487,7 @@ function text_field_widget_settings_form($field, $instance) {
'#title' => t('Size of textfield'), '#title' => t('Size of textfield'),
'#default_value' => $settings['size'], '#default_value' => $settings['size'],
'#required' => TRUE, '#required' => TRUE,
'#element_validate' => array('_element_validate_integer_positive'), '#element_validate' => array('element_validate_integer_positive'),
); );
} }
else { else {
...@@ -490,7 +496,7 @@ function text_field_widget_settings_form($field, $instance) { ...@@ -490,7 +496,7 @@ function text_field_widget_settings_form($field, $instance) {
'#title' => t('Rows'), '#title' => t('Rows'),
'#default_value' => $settings['rows'], '#default_value' => $settings['rows'],
'#required' => TRUE, '#required' => TRUE,
'#element_validate' => array('_element_validate_integer_positive'), '#element_validate' => array('element_validate_integer_positive'),
); );
} }
......
<?php <?php
// $Id: text.test,v 1.30 2010/10/20 01:15:58 dries Exp $
/**
* @file
* Tests for text.module.
*/
class TextFieldTestCase extends DrupalWebTestCase { class TextFieldTestCase extends DrupalWebTestCase {
protected $instance; protected $instance;
...@@ -215,8 +219,8 @@ class TextFieldTestCase extends DrupalWebTestCase { ...@@ -215,8 +219,8 @@ class TextFieldTestCase extends DrupalWebTestCase {
// Display edition form. // Display edition form.
// We should now have a 'text format' selector. // We should now have a 'text format' selector.
$this->drupalGet('test-entity/manage/' . $id . '/edit'); $this->drupalGet('test-entity/manage/' . $id . '/edit');
$this->assertFieldByName("{$this->field_name}[$langcode][0][value]", '', t('Widget is displayed')); $this->assertFieldByName("{$this->field_name}[$langcode][0][value]", NULL, t('Widget is displayed'));
$this->assertFieldByName("{$this->field_name}[$langcode][0][format]", '', t('Format selector is displayed')); $this->assertFieldByName("{$this->field_name}[$langcode][0][format]", NULL, t('Format selector is displayed'));
// Edit and change the text format to the new one that was created. // Edit and change the text format to the new one that was created.
$edit = array( $edit = array(
...@@ -242,6 +246,11 @@ class TextSummaryTestCase extends DrupalWebTestCase { ...@@ -242,6 +246,11 @@ class TextSummaryTestCase extends DrupalWebTestCase {
); );
} }
function setUp() {
parent::setUp();
$this->article_creator = $this->drupalCreateUser(array('create article content', 'edit own article content'));
}
/** /**
* Tests an edge case where the first sentence is a question and * Tests an edge case where the first sentence is a question and
* subsequent sentences are not. This edge case is documented at * subsequent sentences are not. This edge case is documented at
...@@ -376,6 +385,24 @@ class TextSummaryTestCase extends DrupalWebTestCase { ...@@ -376,6 +385,24 @@ class TextSummaryTestCase extends DrupalWebTestCase {
$summary = text_summary($text, $format, $size); $summary = text_summary($text, $format, $size);
$this->assertIdentical($summary, $expected, t('Generated summary "@summary" matches expected "@expected".', array('@summary' => $summary, '@expected' => $expected))); $this->assertIdentical($summary, $expected, t('Generated summary "@summary" matches expected "@expected".', array('@summary' => $summary, '@expected' => $expected)));
} }
/**
* Test sending only summary.
*/
function testOnlyTextSummary() {
// Login as article creator.
$this->drupalLogin($this->article_creator);
// Create article with summary but empty body.
$summary = $this->randomName();
$edit = array(
"title" => $this->randomName(),
"body[und][0][summary]" => $summary,
);
$this->drupalPost('node/add/article', $edit, t('Save'));
$node = $this->drupalGetNodeByTitle($edit['title']);
$this->assertIdentical($node->body['und'][0]['summary'], $summary, t('Article with with summary and no body has been submitted.'));
}
} }
class TextTranslationTestCase extends DrupalWebTestCase { class TextTranslationTestCase extends DrupalWebTestCase {
...@@ -437,7 +464,7 @@ class TextTranslationTestCase extends DrupalWebTestCase { ...@@ -437,7 +464,7 @@ class TextTranslationTestCase extends DrupalWebTestCase {
$node = $this->drupalGetNodeByTitle($edit['title']); $node = $this->drupalGetNodeByTitle($edit['title']);
$this->drupalGet("node/$node->nid/translate"); $this->drupalGet("node/$node->nid/translate");
$this->clickLink(t('add translation')); $this->clickLink(t('add translation'));
$this->assertFieldByXPath("//textarea[@name='body[fr][0][value]']", $body, t('The textfield widget is populated.')); $this->assertFieldByXPath("//textarea[@name='body[$langcode][0][value]']", $body, t('The textfield widget is populated.'));
} }
/** /**
...@@ -457,17 +484,17 @@ class TextTranslationTestCase extends DrupalWebTestCase { ...@@ -457,17 +484,17 @@ class TextTranslationTestCase extends DrupalWebTestCase {
); );
// Create an article with the first body input format set to "Full HTML". // Create an article with the first body input format set to "Full HTML".
$langcode = 'en';
$title = $this->randomName(); $title = $this->randomName();
$edit = array( $edit = array(
'title' => $title, 'title' => $title,
'language' => $langcode, 'language' => 'en',
); );
$this->drupalPost('node/add/article', $edit, t('Save')); $this->drupalPost('node/add/article', $edit, t('Save'));
// Populate the body field: the first item gets the "Full HTML" input // Populate the body field: the first item gets the "Full HTML" input
// format, the second one "Filtered HTML". // format, the second one "Filtered HTML".
$formats = array('full_html', 'filtered_html'); $formats = array('full_html', 'filtered_html');
$langcode = LANGUAGE_NONE;
foreach ($body as $delta => $value) { foreach ($body as $delta => $value) {
$edit = array( $edit = array(
"body[$langcode][$delta][value]" => $value, "body[$langcode][$delta][value]" => $value,
......