You are here

public function FileMiconFormatter::settingsForm in Micon 8

Same name and namespace in other branches
  1. 2.x src/Plugin/Field/FieldFormatter/FileMiconFormatter.php \Drupal\micon\Plugin\Field\FieldFormatter\FileMiconFormatter::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/FileMiconFormatter.php, line 65

Class

FileMiconFormatter
Plugin implementation of the 'file_micon' formatter.

Namespace

Drupal\micon\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'),
  ];
  $elements['text_only'] = [
    '#type' => 'checkbox',
    '#title' => t('Text only'),
    '#default_value' => $this
      ->getSetting('text_only'),
  ];
  foreach (self::mimeGroups() as $id => $data) {
    $key = 'icon_' . $id;
    $elements['icon_' . $key] = [
      '#type' => 'micon',
      '#title' => $this
        ->t('Icon for %type', [
        '%type' => $data['label'],
      ]),
      '#default_value' => $this
        ->getSetting($key),
    ];
  }
  $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,
  ];
  $elements['target'] = [
    '#type' => 'checkbox',
    '#title' => t('Open link in new window'),
    '#return_value' => '_blank',
    '#default_value' => $this
      ->getSetting('target'),
    '#states' => [
      'invisible' => [
        ':input[name*="text_only"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  return $elements;
}