function hook_field_widget_third_party_settings_form

Allow modules to add settings to field widgets provided by other modules.

Parameters

\Drupal\Core\Field\WidgetInterface $plugin: The instantiated field widget plugin.

\Drupal\Core\Field\FieldDefinitionInterface $field_definition: The field definition.

string $form_mode: The entity form mode.

array $form: The (entire) configuration form array.

\Drupal\Core\Form\FormStateInterface $form_state: The form state.

Return value

array Returns the form array to be built.

See also

\Drupal\field_ui\Form\EntityFormDisplayEditForm::thirdPartySettingsForm()

Related topics

3 functions implement hook_field_widget_third_party_settings_form()

Note: the procedural functions in this list are found by pattern matching, so the list may include some functions that are not actually implementations of this hook.

FieldThirdPartyTestHooks::fieldWidgetThirdPartySettingsForm in core/modules/field/tests/modules/field_third_party_test/src/Hook/FieldThirdPartyTestHooks.php
Implements hook_field_widget_third_party_settings_form().
FieldThirdPartyTestHooks::fieldWidgetThirdPartySettingsFormAdditionalImplementation in core/modules/field/tests/modules/field_third_party_test/src/Hook/FieldThirdPartyTestHooks.php
Implements hook_field_widget_third_party_settings_form().
field_third_party_test_field_widget_third_party_settings_form in core/modules/field/tests/modules/field_third_party_test/field_third_party_test.module
Implements hook_field_widget_third_party_settings_form().

File

core/modules/field_ui/field_ui.api.php, line 65

Code

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) {
  $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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.