#841266 by das-peter, yched: Fixed Missing label for boolean fields when adding content
parent
668f7c4470
commit
ff4452f412
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -134,6 +139,22 @@ function options_field_widget_form(&$form, &$form_state, $field, $instance, $lan
|
|||
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 the "On value" as label'),
|
||||
'#default_value' => $instance['widget']['settings']['display_label'],
|
||||
'#weight' => -1,
|
||||
);
|
||||
}
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form element validation handler for options element.
|
||||
*/
|
||||
|
|
|
@ -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')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue