You are here

public function TitleFormatter::settingsForm in Manage display 8

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/TitleFormatter.php, line 50

Class

TitleFormatter
A field formatter for entity titles.

Namespace

Drupal\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'),
    '#access' => $this
      ->canLink(),
  ];
  return $form;
}