You are here

function field_formatter_filter_field_formatter_third_party_settings_form in Field Formatter Filter 8

Same name and namespace in other branches
  1. 2.0.x field_formatter_filter.module \field_formatter_filter_field_formatter_third_party_settings_form()

Adds a 'filter' selection to all text formatters.

Implements hook_field_formatter_third_party_settings_form().

@inheritdoc

See also

hook_field_formatter_third_party_settings_form()

File

./field_formatter_filter.module, line 29
Allows different text format filters to be applied to text fields.

Code

function field_formatter_filter_field_formatter_third_party_settings_form(FormatterInterface $plugin, FieldDefinitionInterface $field_definition, $view_mode, $form, FormStateInterface $form_state) {

  // Only offer this option to text formatters.
  if (!_field_formatter_filter_target_field_type($field_definition
    ->getType())) {
    return NULL;
  }
  $filter_id = $plugin
    ->getThirdPartySetting('field_formatter_filter', 'format');
  $filter_format_options = [
    FALSE => '<none>',
  ];

  /* @var \Drupal\filter\FilterFormatInterface $format */
  $filter_formats = filter_formats();
  foreach ($filter_formats as $format) {
    $filter_format_options[$format
      ->id()] = $format
      ->label();
  }
  $element['format'] = [
    '#type' => 'select',
    '#title' => t('Additional Text Filter/Format'),
    '#options' => $filter_format_options,
    '#default_value' => $filter_id,
    '#description' => t('The selected format will be used <em>instead</em> of whatever the originally selected format is.'),
  ];
  return $element;
}