Security update to Drupal 8.4.6
[yaffs-website] / web / core / modules / field_ui / field_ui.api.php
1 <?php
2
3 /**
4  * @file
5  * Hooks provided by the Field UI module.
6  */
7
8 /**
9  * @addtogroup field_types
10  * @{
11  */
12
13 /**
14  * Allow modules to add settings to field formatters provided by other modules.
15  *
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.
20  * @param $view_mode
21  *   The entity view mode.
22  * @param array $form
23  *   The (entire) configuration form array.
24  * @param \Drupal\Core\Form\FormStateInterface $form_state
25  *   The form state.
26  *
27  * @return array
28  *   Returns the form array to be built.
29  *
30  * @see \Drupal\field_ui\DisplayOverView
31  */
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) {
33   $element = [];
34   // Add a 'my_setting' checkbox to the settings form for 'foo_formatter' field
35   // formatters.
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'),
41     ];
42   }
43   return $element;
44 }
45
46 /**
47  * Allow modules to add settings to field widgets provided by other modules.
48  *
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.
53  * @param $form_mode
54  *   The entity form mode.
55  * @param array $form
56  *   The (entire) configuration form array.
57  * @param \Drupal\Core\Form\FormStateInterface $form_state
58  *   The form state.
59  *
60  * @return array
61  *   Returns the form array to be built.
62  *
63  * @see \Drupal\field_ui\FormDisplayOverView
64  */
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) {
66   $element = [];
67   // Add a 'my_setting' checkbox to the settings form for 'foo_widget' field
68   // widgets.
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'),
74     ];
75   }
76   return $element;
77 }
78
79 /**
80  * Alters the field formatter settings summary.
81  *
82  * @param array $summary
83  *   An array of summary messages.
84  * @param $context
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.
89  *
90  * @see \Drupal\field_ui\DisplayOverView
91  */
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.');
98     }
99   }
100 }
101
102 /**
103  * Alters the field widget settings summary.
104  *
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.
112  *
113  * @see \Drupal\field_ui\FormDisplayOverView
114  */
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.');
121     }
122   }
123 }
124
125 /**
126  * @} End of "addtogroup field_types".
127  */