function hook_field_formatter_third_party_settings_form

Same name and namespace in other branches
  1. 9 core/modules/field_ui/field_ui.api.php \hook_field_formatter_third_party_settings_form()
  2. 10 core/modules/field_ui/field_ui.api.php \hook_field_formatter_third_party_settings_form()
  3. 11.x core/modules/field_ui/field_ui.api.php \hook_field_formatter_third_party_settings_form()

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

Parameters

\Drupal\Core\Field\FormatterInterface $plugin: The instantiated field formatter plugin.

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

string $view_mode: The entity view 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\EntityViewDisplayEditForm::thirdPartySettingsForm()

Related topics

1 function implements hook_field_formatter_third_party_settings_form()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

field_third_party_test_field_formatter_third_party_settings_form in core/modules/field/tests/modules/field_third_party_test/field_third_party_test.module
Implements hook_field_formatter_third_party_settings_form().
2 invocations of hook_field_formatter_third_party_settings_form()
EntityViewDisplayEditForm::thirdPartySettingsForm in core/modules/field_ui/src/Form/EntityViewDisplayEditForm.php
Adds the widget or formatter third party settings forms.
FieldBlock::thirdPartySettingsForm in core/modules/layout_builder/src/Plugin/Block/FieldBlock.php
Adds the formatter third party settings forms.

File

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

Code

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) {
    $element = [];
    // Add a 'my_setting' checkbox to the settings form for 'foo_formatter' field
    // formatters.
    if ($plugin->getPluginId() == 'foo_formatter') {
        $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.