Chris@0: getPluginId() == 'foo_formatter') { Chris@0: $element['my_setting'] = [ Chris@0: '#type' => 'checkbox', Chris@0: '#title' => t('My setting'), Chris@0: '#default_value' => $plugin->getThirdPartySetting('my_module', 'my_setting'), Chris@0: ]; Chris@0: } Chris@0: return $element; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Allow modules to add settings to field widgets provided by other modules. Chris@0: * Chris@0: * @param \Drupal\Core\Field\WidgetInterface $plugin Chris@0: * The instantiated field widget plugin. Chris@0: * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition Chris@0: * The field definition. Chris@18: * @param string $form_mode Chris@0: * The entity form mode. Chris@0: * @param array $form Chris@0: * The (entire) configuration form array. Chris@0: * @param \Drupal\Core\Form\FormStateInterface $form_state Chris@0: * The form state. Chris@0: * Chris@0: * @return array Chris@0: * Returns the form array to be built. Chris@0: * Chris@18: * @see \Drupal\field_ui\Form\EntityFormDisplayEditForm::thirdPartySettingsForm() Chris@0: */ Chris@18: 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: $element = []; Chris@0: // Add a 'my_setting' checkbox to the settings form for 'foo_widget' field Chris@0: // widgets. Chris@0: if ($plugin->getPluginId() == 'foo_widget') { Chris@0: $element['my_setting'] = [ Chris@0: '#type' => 'checkbox', Chris@0: '#title' => t('My setting'), Chris@0: '#default_value' => $plugin->getThirdPartySetting('my_module', 'my_setting'), Chris@0: ]; Chris@0: } Chris@0: return $element; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Alters the field formatter settings summary. Chris@0: * Chris@0: * @param array $summary Chris@0: * An array of summary messages. Chris@18: * @param array $context Chris@0: * An associative array with the following elements: Chris@18: * - formatter: The formatter plugin. Chris@0: * - field_definition: The field definition. Chris@0: * - view_mode: The view mode being configured. Chris@0: * Chris@18: * @see \Drupal\field_ui\Form\EntityViewDisplayEditForm::alterSettingsSummary() Chris@0: */ Chris@18: function hook_field_formatter_settings_summary_alter(array &$summary, array $context) { Chris@0: // Append a message to the summary when an instance of foo_formatter has Chris@0: // mysetting set to TRUE for the current view mode. Chris@0: if ($context['formatter']->getPluginId() == 'foo_formatter') { Chris@0: if ($context['formatter']->getThirdPartySetting('my_module', 'my_setting')) { Chris@0: $summary[] = t('My setting enabled.'); Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Alters the field widget settings summary. Chris@0: * Chris@0: * @param array $summary Chris@0: * An array of summary messages. Chris@0: * @param array $context Chris@0: * An associative array with the following elements: Chris@0: * - widget: The widget object. Chris@0: * - field_definition: The field definition. Chris@0: * - form_mode: The form mode being configured. Chris@0: * Chris@18: * @see \Drupal\field_ui\Form\EntityFormDisplayEditForm::alterSettingsSummary() Chris@0: */ Chris@18: function hook_field_widget_settings_summary_alter(array &$summary, array $context) { Chris@0: // Append a message to the summary when an instance of foo_widget has Chris@0: // mysetting set to TRUE for the current view mode. Chris@0: if ($context['widget']->getPluginId() == 'foo_widget') { Chris@0: if ($context['widget']->getThirdPartySetting('my_module', 'my_setting')) { Chris@0: $summary[] = t('My setting enabled.'); Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * @} End of "addtogroup field_types". Chris@0: */