5 * Hooks provided by the Field UI module.
9 * @addtogroup field_types
14 * Allow modules to add settings to field formatters provided by other modules.
16 * @param \Drupal\Core\Field\FormatterInterface $plugin
17 * The instantiated field formatter plugin.
18 * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
19 * The field definition.
21 * The entity view mode.
23 * The (entire) configuration form array.
24 * @param \Drupal\Core\Form\FormStateInterface $form_state
28 * Returns the form array to be built.
30 * @see \Drupal\field_ui\DisplayOverView
32 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) {
34 // Add a 'my_setting' checkbox to the settings form for 'foo_formatter' field
36 if ($plugin->getPluginId() == 'foo_formatter') {
37 $element['my_setting'] = [
38 '#type' => 'checkbox',
39 '#title' => t('My setting'),
40 '#default_value' => $plugin->getThirdPartySetting('my_module', 'my_setting'),
47 * Allow modules to add settings to field widgets provided by other modules.
49 * @param \Drupal\Core\Field\WidgetInterface $plugin
50 * The instantiated field widget plugin.
51 * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
52 * The field definition.
54 * The entity form mode.
56 * The (entire) configuration form array.
57 * @param \Drupal\Core\Form\FormStateInterface $form_state
61 * Returns the form array to be built.
63 * @see \Drupal\field_ui\FormDisplayOverView
65 function hook_field_widget_third_party_settings_form(\Drupal\Core\Field\WidgetInterface $plugin, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, $form_mode, $form, \Drupal\Core\Form\FormStateInterface $form_state) {
67 // Add a 'my_setting' checkbox to the settings form for 'foo_widget' field
69 if ($plugin->getPluginId() == 'foo_widget') {
70 $element['my_setting'] = [
71 '#type' => 'checkbox',
72 '#title' => t('My setting'),
73 '#default_value' => $plugin->getThirdPartySetting('my_module', 'my_setting'),
80 * Alters the field formatter settings summary.
82 * @param array $summary
83 * An array of summary messages.
85 * An associative array with the following elements:
86 * - formatter: The formatter object.
87 * - field_definition: The field definition.
88 * - view_mode: The view mode being configured.
90 * @see \Drupal\field_ui\DisplayOverView
92 function hook_field_formatter_settings_summary_alter(&$summary, $context) {
93 // Append a message to the summary when an instance of foo_formatter has
94 // mysetting set to TRUE for the current view mode.
95 if ($context['formatter']->getPluginId() == 'foo_formatter') {
96 if ($context['formatter']->getThirdPartySetting('my_module', 'my_setting')) {
97 $summary[] = t('My setting enabled.');
103 * Alters the field widget settings summary.
105 * @param array $summary
106 * An array of summary messages.
107 * @param array $context
108 * An associative array with the following elements:
109 * - widget: The widget object.
110 * - field_definition: The field definition.
111 * - form_mode: The form mode being configured.
113 * @see \Drupal\field_ui\FormDisplayOverView
115 function hook_field_widget_settings_summary_alter(&$summary, $context) {
116 // Append a message to the summary when an instance of foo_widget has
117 // mysetting set to TRUE for the current view mode.
118 if ($context['widget']->getPluginId() == 'foo_widget') {
119 if ($context['widget']->getThirdPartySetting('my_module', 'my_setting')) {
120 $summary[] = t('My setting enabled.');
126 * @} End of "addtogroup field_types".