You are here

public function MiconLinkFormatter::settingsForm in Micon 8

Same name and namespace in other branches
  1. 2.x micon_link/src/Plugin/Field/FieldFormatter/MiconLinkFormatter.php \Drupal\micon_link\Plugin\Field\FieldFormatter\MiconLinkFormatter::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 LinkFormatter::settingsForm

File

micon_link/src/Plugin/Field/FieldFormatter/MiconLinkFormatter.php, line 113

Class

MiconLinkFormatter
Plugin implementation of the 'micon_link' formatter.

Namespace

Drupal\micon_link\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $elements = parent::settingsForm($form, $form_state);
  $elements['title'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Link title'),
    '#default_value' => $this
      ->getSetting('title'),
    '#description' => $this
      ->t('Will be used as the link title unless one has been set on the field. Supports token replacement.'),
    '#weight' => -10,
  ];
  $elements['text_only'] = [
    '#type' => 'checkbox',
    '#title' => t('Text only'),
    '#default_value' => $this
      ->getSetting('text_only'),
    '#weight' => -10,
  ];
  $elements['icon'] = [
    '#type' => 'micon',
    '#title' => $this
      ->t('Link icon'),
    '#default_value' => $this
      ->getSetting('icon'),
    '#description' => $this
      ->t('Will be used as the link icon even if one has been set on the field.'),
    '#weight' => -10,
  ];
  $elements['position'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Icon position'),
    '#options' => [
      'before' => $this
        ->t('Before'),
      'after' => $this
        ->t('After'),
    ],
    '#default_value' => $this
      ->getSetting('position'),
    '#required' => TRUE,
    '#weight' => -10,
  ];
  $visibility = [
    'invisible' => [
      ':input[name*="text_only"]' => [
        'checked' => TRUE,
      ],
    ],
  ];
  $elements['rel']['#states'] = $visibility;
  $elements['target']['#states'] = $visibility;
  return $elements;
}