You are here

public function TextareaWithSummaryAndCounterWidget::settingsForm in Textfield Counter 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 TextareaWithSummaryWidget::settingsForm

File

src/Plugin/Field/FieldWidget/TextareaWithSummaryAndCounterWidget.php, line 42

Class

TextareaWithSummaryAndCounterWidget
Plugin implementation of the 'text_textarea_with_summary_and_counter' widget.

Namespace

Drupal\textfield_counter\Plugin\Field\FieldWidget

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $form = parent::settingsForm($form, $form_state);
  $form['general_header'] = [
    '#prefix' => '<h3>',
    '#suffix' => '</h3>',
    '#markup' => $this
      ->t('General Settings'),
    '#weight' => -149,
  ];
  $this
    ->addCounterPositionSettingsFormElement($form);
  $form['counter_position']['#weight'] = -139;
  $this
    ->addTextCountStatusMessageSettingsFormElement($form);
  $form['textcount_status_message']['#weight'] = -129;
  $form['summary_header'] = [
    '#prefix' => '<h3>',
    '#suffix' => '</h3>',
    '#markup' => $this
      ->t('Summary'),
    '#weight' => -99,
  ];
  $form['enable_summary'] = [
    '#title' => $this
      ->t('Enable summary field'),
    '#type' => 'checkbox',
    '#weight' => -89,
    '#default_value' => $this
      ->getSetting('enable_summary'),
    '#attributes' => [
      'data-textfield-counter-selector' => 'enable-summary-checkbox',
    ],
  ];
  $form['show_summary']['#weight'] = -79;
  $form['show_summary']['#states']['visible']['[data-textfield-counter-selector="enable-summary-checkbox"]'] = [
    'checked' => TRUE,
  ];
  $form['summary_rows']['#weight'] = -69;
  $form['summary_rows']['#states']['visible']['[data-textfield-counter-selector="enable-summary-checkbox"]'] = [
    'checked' => TRUE,
  ];
  $this
    ->addSummaryMaxLengthSettingsFormElement($form);
  $form['textarea_header'] = [
    '#prefix' => '<h3>',
    '#suffix' => '</h3>',
    '#markup' => $this
      ->t('Textarea'),
    '#weight' => -49,
  ];
  $this
    ->addMaxlengthSettingsFormElement($form);
  $this
    ->addJsPreventSubmitSettingsFormElement($form);
  $this
    ->addCountHtmlSettingsFormElement($form);
  return $form;
}