You are here

public function TitleStyleTextFieldFormatter::settingsForm in Title Field for Manage Display 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldFormatter/TitleStyleTextFieldFormatter.php \Drupal\title_field_for_manage_display\Plugin\Field\FieldFormatter\TitleStyleTextFieldFormatter::settingsForm()

Returns a form to configure settings for the formatter.

Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the formatter. The field_ui module takes care of handling submitted form values.

Parameters

array $form: The form where the settings form is being included in.

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

Return value

array The form elements for the formatter settings.

Overrides FormatterBase::settingsForm

File

src/Plugin/Field/FieldFormatter/TitleStyleTextFieldFormatter.php, line 56

Class

TitleStyleTextFieldFormatter
Plugin implementation of the 'title_style_text_field_formatter' formatter.

Namespace

Drupal\title_field_for_manage_display\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $form = parent::settingsForm($form, $form_state);
  $heading_options = [
    'span' => 'span',
    'div' => 'div',
  ];
  foreach (range(1, 5) as $level) {
    $heading_options['h' . $level] = 'H' . $level;
  }
  $form['tag'] = [
    '#title' => $this
      ->t('Tag'),
    '#type' => 'select',
    '#description' => $this
      ->t('Select the tag which will be wrapped around the title.'),
    '#options' => $heading_options,
    '#default_value' => $this
      ->getSetting('tag'),
  ];
  $form['linked'] = [
    '#title' => $this
      ->t('Link to the Content'),
    '#type' => 'checkbox',
    '#description' => $this
      ->t('Wrap the title with a link to the content.'),
    '#default_value' => $this
      ->getSetting('linked'),
  ];
  $form['classes'] = [
    '#title' => $this
      ->t('Classes'),
    '#type' => 'textfield',
    '#default_value' => $this
      ->getSetting('classes'),
  ];
  return $form;
}