summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/field/modules/options/options.module21
-rw-r--r--modules/field/modules/options/options.test56
2 files changed, 77 insertions, 0 deletions
diff --git a/modules/field/modules/options/options.module b/modules/field/modules/options/options.module
index e536c08c6..538a3ddfd 100644
--- a/modules/field/modules/options/options.module
+++ b/modules/field/modules/options/options.module
@@ -61,6 +61,7 @@ function options_field_widget_info() {
'behaviors' => array(
'multiple values' => FIELD_BEHAVIOR_CUSTOM,
),
+ 'settings' => array('display_label' => 0),
),
);
}
@@ -122,6 +123,10 @@ function options_field_widget_form(&$form, &$form_state, $field, $instance, $lan
);
// Override the title from the incoming $element.
$element['#title'] = isset($options[$on_value]) ? $options[$on_value] : '';
+
+ if ($instance['widget']['settings']['display_label']) {
+ $element['#title'] = $instance['label'];
+ }
break;
}
@@ -135,6 +140,22 @@ function options_field_widget_form(&$form, &$form_state, $field, $instance, $lan
}
/**
+ * 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 the "On value" as label'),
+ '#default_value' => $instance['widget']['settings']['display_label'],
+ '#weight' => -1,
+ );
+ }
+ return $form;
+}
+
+/**
* Form element validation handler for options element.
*/
function options_field_widget_validate($element, &$form_state) {
diff --git a/modules/field/modules/options/options.test b/modules/field/modules/options/options.test
index 110ab5767..e90bf6172 100644
--- a/modules/field/modules/options/options.test
+++ b/modules/field/modules/options/options.test
@@ -453,6 +453,62 @@ class OptionsWidgetsTestCase extends FieldTestCase {
// Display form: with 'off' value, option is unchecked.
$this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit');
$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'] = "0|0\n1|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 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 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')
+ );
}
}