diff --git a/core/modules/field_ui/field_ui.api.php b/core/modules/field_ui/field_ui.api.php index ef9e338..5277bce 100644 --- a/core/modules/field_ui/field_ui.api.php +++ b/core/modules/field_ui/field_ui.api.php @@ -185,6 +185,15 @@ function hook_field_formatter_settings_form($field, $instance, $view_mode, $form * - 'form': The (entire) configuration form array. */ function hook_field_formatter_settings_form_alter(&$element, &$form_state, $context) { + // Add a mysetting checkbox to the settings form for foo_field fields. + if ($context['field']['type'] == 'foo_field') { + $display = $context['instance']['display'][$context['view_mode']]; + $element['mysetting'] = array( + '#type' = 'checkbox', + '#title' = t('My setting'), + '#default_value' = $display['settings']['mysetting'], + ); + } } /** @@ -199,6 +208,14 @@ function hook_field_formatter_settings_form_alter(&$element, &$form_state, $cont * - 'view_mode': The view mode being configured. */ function hook_field_formatter_settings_summary_alter(&$summary, $context) { + // Append a message to the summary when an instance of foo_field has + // mysetting set to TRUE for the current view mode. + if ($context['field']['type'] == 'foo_field') { + $display = $context['instance']['display'][$context['view_mode']]; + if ($display['settings']['mysetting']) { + $summary .= '
' . t('My setting enabled.'); + } + } } /** diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageDisplayTest.php b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageDisplayTest.php index 1bf2a99..e15f079 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageDisplayTest.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageDisplayTest.php @@ -76,19 +76,21 @@ class ManageDisplayTest extends FieldUiTestBase { $this->assertEqual($current_format, $format, t('The formatter was updated.')); $this->assertEqual($current_setting_value, $setting_value, t('The setting was updated.')); - // Assert hook_field_formatter_settings_summary_alter is called. + // Assert that hook_field_formatter_settings_summary_alter() is called. $this->assertText('field_test_field_formatter_settings_summary_alter'); - // Click on the formatter settings button to open the formatter settings form. + // Click on the formatter settings button to open the formatter settings + // form. $this->drupalPostAJAX(NULL, array(), "field_test_formatter_settings_edit"); - // Assert the field added in field_test_field_formatter_settings_form_alter is present. + // Assert that the field added in + // field_test_field_formatter_settings_form_alter() is present. $fieldname = 'fields[field_test][settings_edit_form][settings][field_test_formatter_settings_form_alter]'; - $this->assertField($fieldname, t('Field added in hook_ield_formatter_settings_form_alter is present.')); + $this->assertField($fieldname, 'The field added in hook_field_formatter_settings_form_alter() is present on the settings form.')); $edit = array($fieldname => 'foo'); $this->drupalPostAJAX(NULL, $edit, "field_test_formatter_settings_update"); - // Open the formatter settings form again to check if the settings are updated. + // Confirm that the settings are updated on the settings form. $this->drupalPostAJAX(NULL, array(), "field_test_formatter_settings_edit"); $this->assertFieldByName($fieldname, 'foo'); }