You are here

public function LinkWithAttributesWidget::settingsForm in Link Attributes widget 8

Returns a form to configure settings for the widget.

Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the widget. 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 definition for the widget settings.

Overrides LinkWidget::settingsForm

File

src/Plugin/Field/FieldWidget/LinkWithAttributesWidget.php, line 129

Class

LinkWithAttributesWidget
Plugin implementation of the 'link' widget.

Namespace

Drupal\link_attributes\Plugin\Field\FieldWidget

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $element = parent::settingsForm($form, $form_state);
  $options = array_map(function ($plugin_definition) {
    return $plugin_definition['title'];
  }, $this->linkAttributesManager
    ->getDefinitions());
  $selected = array_keys(array_filter($this
    ->getSetting('enabled_attributes')));
  $element['enabled_attributes'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Enabled attributes'),
    '#options' => $options,
    '#default_value' => array_combine($selected, $selected),
    '#description' => $this
      ->t('Select the attributes to allow the user to edit.'),
  ];
  return $element;
}