You are here

public function GutenbergTextFormatter::settingsForm in Gutenberg 8.2

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

File

src/Plugin/Field/FieldFormatter/GutenbergTextFormatter.php, line 38

Class

GutenbergTextFormatter
Plugin implementation of the 'gutenberg_text' formatter.

Namespace

Drupal\gutenberg\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $user = \Drupal::currentUser();
  $formats = filter_formats($user);
  $options = [];
  foreach ($formats as $format) {
    $dependencies = $format
      ->getDependencies();
    if (isset($dependencies['module']) && in_array('gutenberg', $dependencies['module'], TRUE)) {

      // Include formats which rely on the gutenberg module.
      $options[$format
        ->id()] = $format
        ->label();
    }
  }
  $element = parent::settingsForm($form, $form_state);
  $element['format'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Gutenberg format'),
    '#options' => $options,
    '#default_value' => $this
      ->getSetting('format'),
    '#required' => TRUE,
  ];
  $element['content_only'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Content only'),
    '#description' => $this
      ->t('Render the field content without the field wrapper.'),
    '#default_value' => $this
      ->getSetting('content_only'),
  ];
  return $element;
}