You are here

public function ColorboxFieldFormatter::settingsForm in Colorbox field formatter 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/Field/FieldFormatter/ColorboxFieldFormatter.php \Drupal\colorbox_field_formatter\Plugin\Field\FieldFormatter\ColorboxFieldFormatter::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

2 calls to ColorboxFieldFormatter::settingsForm()
ColorboxFieldFormatterEntityreference::settingsForm in src/Plugin/Field/FieldFormatter/ColorboxFieldFormatterEntityreference.php
Returns a form to configure settings for the formatter.
ColorboxFieldFormatterImage::settingsForm in src/Plugin/Field/FieldFormatter/ColorboxFieldFormatterImage.php
Returns a form to configure settings for the formatter.
2 methods override ColorboxFieldFormatter::settingsForm()
ColorboxFieldFormatterEntityreference::settingsForm in src/Plugin/Field/FieldFormatter/ColorboxFieldFormatterEntityreference.php
Returns a form to configure settings for the formatter.
ColorboxFieldFormatterImage::settingsForm in src/Plugin/Field/FieldFormatter/ColorboxFieldFormatterImage.php
Returns a form to configure settings for the formatter.

File

src/Plugin/Field/FieldFormatter/ColorboxFieldFormatter.php, line 108

Class

ColorboxFieldFormatter
Plugin implementation of the 'colorbox_field_formatter' formatter.

Namespace

Drupal\colorbox_field_formatter\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $form = parent::settingsForm($form, $form_state);
  $form['style'] = [
    '#title' => $this
      ->t('Style of colorbox'),
    '#type' => 'select',
    '#default_value' => $this
      ->getSetting('style'),
    '#options' => $this
      ->getStyles(),
    '#attributes' => [
      'class' => [
        'colorbox-field-formatter-style',
      ],
    ],
  ];
  $form['link_type'] = [
    '#title' => $this
      ->t('Link colorbox to'),
    '#type' => 'select',
    '#default_value' => $this
      ->getSetting('link_type'),
    '#options' => $this
      ->getLinkTypes(),
    '#attributes' => [
      'class' => [
        'colorbox-field-formatter-link-type',
      ],
    ],
    '#states' => [
      'visible' => [
        'select.colorbox-field-formatter-style' => [
          'value' => 'default',
        ],
      ],
    ],
  ];
  $form['link'] = [
    '#title' => $this
      ->t('URI'),
    '#type' => 'textfield',
    '#default_value' => $this
      ->getSetting('link'),
    '#states' => [
      'visible' => [
        'select.colorbox-field-formatter-style' => [
          'value' => 'default',
        ],
        'select.colorbox-field-formatter-link-type' => [
          'value' => 'manual',
        ],
      ],
    ],
  ];
  if (isset($form['#entity_type']) && $this->moduleHandler
    ->moduleExists('token')) {
    $form['token_help_wrapper'] = [
      '#type' => 'container',
      '#states' => [
        'visible' => [
          'select.colorbox-field-formatter-style' => [
            'value' => 'default',
          ],
          'select.colorbox-field-formatter-link-type' => [
            'value' => 'manual',
          ],
        ],
      ],
    ];
    $form['token_help_wrapper']['token_help'] = [
      '#theme' => 'token_tree',
      '#token_types' => [
        'entity' => $form['#entity_type'],
      ],
      '#global_types' => FALSE,
    ];
  }
  $form['inline_selector'] = [
    '#title' => $this
      ->t('Inline selector'),
    '#type' => 'textfield',
    '#default_value' => $this
      ->getSetting('inline_selector'),
    '#states' => [
      'visible' => [
        'select.colorbox-field-formatter-style' => [
          'value' => 'colorbox-inline',
        ],
      ],
    ],
  ];
  $form['width'] = [
    '#title' => $this
      ->t('Width'),
    '#type' => 'textfield',
    '#default_value' => $this
      ->getSetting('width'),
  ];
  $form['height'] = [
    '#title' => $this
      ->t('Height'),
    '#type' => 'textfield',
    '#default_value' => $this
      ->getSetting('height'),
  ];
  $form['iframe'] = [
    '#title' => $this
      ->t('iFrame Mode'),
    '#type' => 'checkbox',
    '#default_value' => $this
      ->getSetting('iframe'),
  ];
  $form['anchor'] = [
    '#title' => $this
      ->t('Anchor'),
    '#type' => 'textfield',
    '#default_value' => $this
      ->getSetting('anchor'),
  ];
  $form['class'] = [
    '#title' => $this
      ->t('Class'),
    '#type' => 'textfield',
    '#default_value' => $this
      ->getSetting('class'),
  ];
  $form['rel'] = [
    '#title' => $this
      ->t('Rel'),
    '#type' => 'textfield',
    '#default_value' => $this
      ->getSetting('rel'),
    '#description' => $this
      ->t('This can be used to identify a group for Colorbox to cycle through.'),
  ];
  return $form;
}