X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Ffield_ui%2Ffield_ui.api.php;fp=web%2Fcore%2Fmodules%2Ffield_ui%2Ffield_ui.api.php;h=92cbaf2700ec017e31ea598fe6cd633d96a271ca;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/field_ui/field_ui.api.php b/web/core/modules/field_ui/field_ui.api.php new file mode 100644 index 000000000..92cbaf270 --- /dev/null +++ b/web/core/modules/field_ui/field_ui.api.php @@ -0,0 +1,127 @@ +getPluginId() == 'foo_formatter') { + $element['my_setting'] = [ + '#type' => 'checkbox', + '#title' => t('My setting'), + '#default_value' => $plugin->getThirdPartySetting('my_module', 'my_setting'), + ]; + } + return $element; +} + +/** + * Allow modules to add settings to field widgets provided by other modules. + * + * @param \Drupal\Core\Field\WidgetInterface $plugin + * The instantiated field widget plugin. + * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition + * The field definition. + * @param $form_mode + * The entity form mode. + * @param array $form + * The (entire) configuration form array. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The form state. + * + * @return array + * Returns the form array to be built. + * + * @see \Drupal\field_ui\FormDisplayOverView + */ +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) { + $element = []; + // Add a 'my_setting' checkbox to the settings form for 'foo_widget' field + // widgets. + if ($plugin->getPluginId() == 'foo_widget') { + $element['my_setting'] = [ + '#type' => 'checkbox', + '#title' => t('My setting'), + '#default_value' => $plugin->getThirdPartySetting('my_module', 'my_setting'), + ]; + } + return $element; +} + +/** + * Alters the field formatter settings summary. + * + * @param array $summary + * An array of summary messages. + * @param $context + * An associative array with the following elements: + * - formatter: The formatter object. + * - field_definition: The field definition. + * - view_mode: The view mode being configured. + * + * @see \Drupal\field_ui\DisplayOverView + */ +function hook_field_formatter_settings_summary_alter(&$summary, $context) { + // Append a message to the summary when an instance of foo_formatter has + // mysetting set to TRUE for the current view mode. + if ($context['formatter']->getPluginId() == 'foo_formatter') { + if ($context['formatter']->getThirdPartySetting('my_module', 'my_setting')) { + $summary[] = t('My setting enabled.'); + } + } +} + +/** + * Alters the field widget settings summary. + * + * @param array $summary + * An array of summary messages. + * @param array $context + * An associative array with the following elements: + * - widget: The widget object. + * - field_definition: The field definition. + * - form_mode: The form mode being configured. + * + * @see \Drupal\field_ui\FormDisplayOverView + */ +function hook_field_widget_settings_summary_alter(&$summary, $context) { + // Append a message to the summary when an instance of foo_widget has + // mysetting set to TRUE for the current view mode. + if ($context['widget']->getPluginId() == 'foo_widget') { + if ($context['widget']->getThirdPartySetting('my_module', 'my_setting')) { + $summary[] = t('My setting enabled.'); + } + } +} + +/** + * @} End of "addtogroup field_types". + */