You are here

public function LinkedAndWrapped::settingsForm in Title 8.2

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/LinkedAndWrapped.php, line 61

Class

LinkedAndWrapped
A field formatter for linking and wrapping text.

Namespace

Drupal\title\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $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 text.'),
    '#options' => $heading_options,
    '#default_value' => $this
      ->getSetting('tag'),
  ];
  $form['linked'] = [
    '#title' => $this
      ->t('Link to the Content'),
    '#type' => 'checkbox',
    '#description' => $this
      ->t('Wrap the text 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;
}