annotate core/modules/field_ui/field_ui.api.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents af1871eacc83
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /**
Chris@0 4 * @file
Chris@0 5 * Hooks provided by the Field UI module.
Chris@0 6 */
Chris@0 7
Chris@0 8 /**
Chris@0 9 * @addtogroup field_types
Chris@0 10 * @{
Chris@0 11 */
Chris@0 12
Chris@0 13 /**
Chris@0 14 * Allow modules to add settings to field formatters provided by other modules.
Chris@0 15 *
Chris@0 16 * @param \Drupal\Core\Field\FormatterInterface $plugin
Chris@0 17 * The instantiated field formatter plugin.
Chris@0 18 * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
Chris@0 19 * The field definition.
Chris@18 20 * @param string $view_mode
Chris@0 21 * The entity view mode.
Chris@0 22 * @param array $form
Chris@0 23 * The (entire) configuration form array.
Chris@0 24 * @param \Drupal\Core\Form\FormStateInterface $form_state
Chris@0 25 * The form state.
Chris@0 26 *
Chris@0 27 * @return array
Chris@0 28 * Returns the form array to be built.
Chris@0 29 *
Chris@18 30 * @see \Drupal\field_ui\Form\EntityViewDisplayEditForm::thirdPartySettingsForm()
Chris@0 31 */
Chris@18 32 function hook_field_formatter_third_party_settings_form(\Drupal\Core\Field\FormatterInterface $plugin, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, $view_mode, array $form, \Drupal\Core\Form\FormStateInterface $form_state) {
Chris@0 33 $element = [];
Chris@0 34 // Add a 'my_setting' checkbox to the settings form for 'foo_formatter' field
Chris@0 35 // formatters.
Chris@0 36 if ($plugin->getPluginId() == 'foo_formatter') {
Chris@0 37 $element['my_setting'] = [
Chris@0 38 '#type' => 'checkbox',
Chris@0 39 '#title' => t('My setting'),
Chris@0 40 '#default_value' => $plugin->getThirdPartySetting('my_module', 'my_setting'),
Chris@0 41 ];
Chris@0 42 }
Chris@0 43 return $element;
Chris@0 44 }
Chris@0 45
Chris@0 46 /**
Chris@0 47 * Allow modules to add settings to field widgets provided by other modules.
Chris@0 48 *
Chris@0 49 * @param \Drupal\Core\Field\WidgetInterface $plugin
Chris@0 50 * The instantiated field widget plugin.
Chris@0 51 * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
Chris@0 52 * The field definition.
Chris@18 53 * @param string $form_mode
Chris@0 54 * The entity form mode.
Chris@0 55 * @param array $form
Chris@0 56 * The (entire) configuration form array.
Chris@0 57 * @param \Drupal\Core\Form\FormStateInterface $form_state
Chris@0 58 * The form state.
Chris@0 59 *
Chris@0 60 * @return array
Chris@0 61 * Returns the form array to be built.
Chris@0 62 *
Chris@18 63 * @see \Drupal\field_ui\Form\EntityFormDisplayEditForm::thirdPartySettingsForm()
Chris@0 64 */
Chris@18 65 function hook_field_widget_third_party_settings_form(\Drupal\Core\Field\WidgetInterface $plugin, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, $form_mode, array $form, \Drupal\Core\Form\FormStateInterface $form_state) {
Chris@0 66 $element = [];
Chris@0 67 // Add a 'my_setting' checkbox to the settings form for 'foo_widget' field
Chris@0 68 // widgets.
Chris@0 69 if ($plugin->getPluginId() == 'foo_widget') {
Chris@0 70 $element['my_setting'] = [
Chris@0 71 '#type' => 'checkbox',
Chris@0 72 '#title' => t('My setting'),
Chris@0 73 '#default_value' => $plugin->getThirdPartySetting('my_module', 'my_setting'),
Chris@0 74 ];
Chris@0 75 }
Chris@0 76 return $element;
Chris@0 77 }
Chris@0 78
Chris@0 79 /**
Chris@0 80 * Alters the field formatter settings summary.
Chris@0 81 *
Chris@0 82 * @param array $summary
Chris@0 83 * An array of summary messages.
Chris@18 84 * @param array $context
Chris@0 85 * An associative array with the following elements:
Chris@18 86 * - formatter: The formatter plugin.
Chris@0 87 * - field_definition: The field definition.
Chris@0 88 * - view_mode: The view mode being configured.
Chris@0 89 *
Chris@18 90 * @see \Drupal\field_ui\Form\EntityViewDisplayEditForm::alterSettingsSummary()
Chris@0 91 */
Chris@18 92 function hook_field_formatter_settings_summary_alter(array &$summary, array $context) {
Chris@0 93 // Append a message to the summary when an instance of foo_formatter has
Chris@0 94 // mysetting set to TRUE for the current view mode.
Chris@0 95 if ($context['formatter']->getPluginId() == 'foo_formatter') {
Chris@0 96 if ($context['formatter']->getThirdPartySetting('my_module', 'my_setting')) {
Chris@0 97 $summary[] = t('My setting enabled.');
Chris@0 98 }
Chris@0 99 }
Chris@0 100 }
Chris@0 101
Chris@0 102 /**
Chris@0 103 * Alters the field widget settings summary.
Chris@0 104 *
Chris@0 105 * @param array $summary
Chris@0 106 * An array of summary messages.
Chris@0 107 * @param array $context
Chris@0 108 * An associative array with the following elements:
Chris@0 109 * - widget: The widget object.
Chris@0 110 * - field_definition: The field definition.
Chris@0 111 * - form_mode: The form mode being configured.
Chris@0 112 *
Chris@18 113 * @see \Drupal\field_ui\Form\EntityFormDisplayEditForm::alterSettingsSummary()
Chris@0 114 */
Chris@18 115 function hook_field_widget_settings_summary_alter(array &$summary, array $context) {
Chris@0 116 // Append a message to the summary when an instance of foo_widget has
Chris@0 117 // mysetting set to TRUE for the current view mode.
Chris@0 118 if ($context['widget']->getPluginId() == 'foo_widget') {
Chris@0 119 if ($context['widget']->getThirdPartySetting('my_module', 'my_setting')) {
Chris@0 120 $summary[] = t('My setting enabled.');
Chris@0 121 }
Chris@0 122 }
Chris@0 123 }
Chris@0 124
Chris@0 125 /**
Chris@0 126 * @} End of "addtogroup field_types".
Chris@0 127 */