You are here

public function ButtonLinkFormatter::settingsForm in Button Link Formatter 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 LinkFormatter::settingsForm

File

src/Plugin/Field/FieldFormatter/ButtonLinkFormatter.php, line 44

Class

ButtonLinkFormatter
Plugin implementation of the 'link_separate' formatter.

Namespace

Drupal\button_link\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $parentForm, FormStateInterface $form_state) {
  $parentForm = parent::settingsForm($parentForm, $form_state);
  $settings = $this
    ->getSettings();
  $form['link_text'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Link text, leave empty for default'),
    '#default_value' => $settings['link_text'],
  ];
  $form['btn_type'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Button type'),
    '#default_value' => $settings['btn_type'],
    '#options' => [
      'btn-default' => $this
        ->t('Default'),
      'btn-primary' => $this
        ->t('Primary'),
      'btn-secondary' => $this
        ->t('Secondary'),
      'btn-success' => $this
        ->t('Success'),
      'btn-info' => $this
        ->t('Info'),
      'btn-warning' => $this
        ->t('Warning'),
      'btn-danger' => $this
        ->t('Danger'),
      'btn-light' => $this
        ->t('Light'),
      'btn-dark' => $this
        ->t('Dark'),
      'btn-link' => $this
        ->t('Link'),
    ],
    '#required' => TRUE,
  ];
  $form['btn_size'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Button size'),
    '#default_value' => $settings['btn_size'],
    '#empty_option' => $this
      ->t('Default'),
    '#options' => [
      'btn-lg' => $this
        ->t('Large'),
      'btn-sm' => $this
        ->t('Small'),
      'btn-xs' => $this
        ->t('Extra Small'),
    ],
  ];
  $form['icon_class'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Classes for icons, example: "fa fa-anchor".'),
    '#default_value' => $settings['icon_class'],
  ];
  $form['disable_btn_role'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t("Disable default role 'button'"),
    '#default_value' => $settings['disable_btn_role'],
  ];
  $form['btn_block'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Block level?'),
    '#return_value' => 'btn-block',
    '#default_value' => $settings['btn_block'],
  ];
  return $form + $parentForm;
}