You are here

public function PictureBackgroundFormatter::settingsForm in Picture Background 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 ResponsiveImageFormatter::settingsForm

File

src/Plugin/Field/FieldFormatter/PictureBackgroundFormatter.php, line 41

Class

PictureBackgroundFormatter
Plugin implementation of the 'picture_background_formatter' formatter.

Namespace

Drupal\picture_background_formatter\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $elements = parent::settingsForm($form, $form_state);
  unset($elements['image_link']);
  $token_types = [
    $this->fieldDefinition
      ->getTargetEntityTypeId(),
  ];
  $elements['selector'] = array(
    '#type' => 'textfield',
    '#title' => t('Selector'),
    '#required' => TRUE,
    '#description' => t('CSS Selector for background image.'),
    '#default_value' => $this
      ->getSetting('selector'),
    '#token_types' => $token_types,
    '#element_validate' => 'token_element_validate',
  );
  $elements['tokens'] = [
    '#theme' => 'token_tree_link',
    '#token_types' => $token_types,
    '#global_types' => TRUE,
    '#show_nested' => FALSE,
  ];
  return $elements;
}