You are here

public function EditorNoteWidget::settingsForm in Editor Notes 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 WidgetBase::settingsForm

File

src/Plugin/Field/FieldWidget/EditorNoteWidget.php, line 93

Class

EditorNoteWidget
Editor note widget.

Namespace

Drupal\editor_note\Plugin\Field\FieldWidget

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $element = parent::settingsForm($form, $form_state);

  // @todo: implement support for text formats.
  $element['formatted'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Formatted'),
    '#default_value' => $this
      ->getSetting('formatted'),
    '#weight' => -1,
    '#disabled' => TRUE,
  ];
  $options = [];
  foreach (filter_formats() as $format) {
    $options[$format
      ->id()] = $format
      ->label();
  }
  $field_name = $this->fieldDefinition
    ->getName();
  $element['default_format'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Default format'),
    '#options' => $options,
    '#default_value' => $this
      ->getSetting('default_format'),
    '#states' => [
      'visible' => [
        ':input[name="fields[' . $field_name . '][settings_edit_form][settings][formatted]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $element['limit'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Display a specified number of items.'),
    '#description' => $this
      ->t('Display a specified number of items. Set 0 for no limit.'),
    '#default_value' => $this
      ->getSetting('limit'),
  ];

  //    Not fully implemented pagination flow.
  //    @see https://www.drupal.org/project/editor_note/issues/3087584
  //    $element['pager_enabled'] = [
  //      '#type' => 'checkbox',
  //      '#title' => t('Enable pagination'),
  //      '#default_value' => $this->getSetting('pager_enabled'),
  //      '#description' => t('Whether to display pagination if number of notes added is greater that can be displayed.'),
  //      '#states' => [
  //        'invisible' => [
  //          ':input[name="fields[' . $field_name . '][settings_edit_form][settings][limit]"]' => ['value' => 0],
  //        ],
  //      ],
  //    ];
  //
  //    $element['pager_below'] = [
  //      '#type' => 'checkbox',
  //      '#title' => t('Pagination below notes table'),
  //      '#default_value' => $this->getSetting('pager_below'),
  //      '#description' => t('Displays pagination below the notes table, if unchecked pagination displays above the table.'),
  //      '#states' => [
  //        'visible' => [
  //          ':input[name="fields[' . $field_name . '][settings_edit_form][settings][pager_enabled]"]' => ['checked' => TRUE],
  //        ],
  //      ],
  //    ];
  return $element;
}