You are here

public function TextFieldCounterWidgetTrait::addCounterPositionSettingsFormElement in Textfield Counter 8

Adds a form element to set the position of the text counter.

Parameters

array $form: The form render array to which the element should be added.

bool $storageSettingMaxlengthField: Whether or not the field has storage settings that include a maximum length. Such fields allow for using the storage settings rather than the wiget setting.

5 calls to TextFieldCounterWidgetTrait::addCounterPositionSettingsFormElement()
StringTextareaWithCounterWidget::settingsForm in src/Plugin/Field/FieldWidget/StringTextareaWithCounterWidget.php
Returns a form to configure settings for the widget.
StringTextfieldWithCounterWidget::settingsForm in src/Plugin/Field/FieldWidget/StringTextfieldWithCounterWidget.php
Returns a form to configure settings for the widget.
TextareaWithCounterWidget::settingsForm in src/Plugin/Field/FieldWidget/TextareaWithCounterWidget.php
Returns a form to configure settings for the widget.
TextareaWithSummaryAndCounterWidget::settingsForm in src/Plugin/Field/FieldWidget/TextareaWithSummaryAndCounterWidget.php
Returns a form to configure settings for the widget.
TextfieldWithCounterWidget::settingsForm in src/Plugin/Field/FieldWidget/TextfieldWithCounterWidget.php
Returns a form to configure settings for the widget.

File

src/Plugin/Field/FieldWidget/TextFieldCounterWidgetTrait.php, line 68

Class

TextFieldCounterWidgetTrait
Textfield counter trait. Adds textfield counting functionality.

Namespace

Drupal\textfield_counter\Plugin\Field\FieldWidget

Code

public function addCounterPositionSettingsFormElement(array &$form, $storageSettingMaxlengthField = FALSE) {
  $form['counter_position'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Counter position'),
    '#options' => [
      'before' => $this
        ->translateValue('before'),
      'after' => $this
        ->translateValue('after'),
    ],
    '#default_value' => $this
      ->getSetting('counter_position'),
  ];
  if ($storageSettingMaxlengthField) {
    $form['counter_position']['#states'] = [
      'invisible' => [
        ':input[name="fields[' . $this->fieldDefinition
          ->getName() . '][settings_edit_form][settings][use_field_maxlength]"]' => [
          'checked' => FALSE,
        ],
        ':input[name="fields[' . $this->fieldDefinition
          ->getName() . '][settings_edit_form][settings][maxlength]"]' => [
          'value' => 0,
        ],
      ],
    ];
  }
  else {
    $form['counter_position']['#states'] = [
      'invisible' => [
        ':input[name="fields[' . $this->fieldDefinition
          ->getName() . '][settings_edit_form][settings][maxlength]"]' => [
          'value' => 0,
        ],
      ],
    ];
  }
}