function hook_field_formatter_third_party_settings_form

hook_field_formatter_third_party_settings_form(\Drupal\Core\Field\FormatterInterface $plugin, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, $view_mode, $form, \Drupal\Core\Form\FormStateInterface $form_state)

Allow modules to add settings to field formatters provided by other modules.

Parameters

\Drupal\Core\Field\FormatterInterface $plugin: The instantiated field formatter plugin.

\Drupal\Core\Field\FieldDefinitionInterface $field_definition: The field definition.

$view_mode: The entity view mode.

array $form: The (entire) configuration form array.

\Drupal\Core\Form\FormStateInterface $form_state: The form state.

Return value

array Returns the form array to be built.

See also

\Drupal\field_ui\DisplayOverView

Related topics

Field Types API
Defines field, widget, display formatter, and storage types.

File

core/modules/field_ui/field_ui.api.php, line 32
Hooks provided by the Field UI module.

Code

function hook_field_formatter_third_party_settings_form(\Drupal\Core\Field\FormatterInterface $plugin, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, $view_mode, $form, \Drupal\Core\Form\FormStateInterface $form_state) {
  $element = array();
  // Add a 'my_setting' checkbox to the settings form for 'foo_formatter' field
  // formatters.
  if ($plugin->getPluginId() == 'foo_formatter') {
    $element['my_setting'] = array(
      '#type' => 'checkbox',
      '#title' => t('My setting'),
      '#default_value' => $plugin->getThirdPartySetting('my_module', 'my_setting'),
    );
  }
  return $element;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!field_ui!field_ui.api.php/function/hook_field_formatter_third_party_settings_form/8.1.x