You are here

public function TextFieldCounterWidgetTrait::addTextCountStatusMessageSettingsFormElement in Textfield Counter 8

Adds a form element to set the status message to be shown to users.

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::addTextCountStatusMessageSettingsFormElement()
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 187

Class

TextFieldCounterWidgetTrait
Textfield counter trait. Adds textfield counting functionality.

Namespace

Drupal\textfield_counter\Plugin\Field\FieldWidget

Code

public function addTextCountStatusMessageSettingsFormElement(array &$form, $storageSettingMaxlengthField = FALSE) {
  $form['textcount_status_message'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Message shown to users'),
    '#default_value' => $this
      ->getSetting('textcount_status_message'),
    '#description' => $this
      ->t('Enter the message to show to users indicating the current status of the character count. The variables <strong>@maxlength</strong>, <strong>@current_length</strong> and <strong>@remaining_count</strong> can be used in this field. For the real-time counter to work, said variables must be wrapped in HTML span tags with their classes respectively set to <strong>maxlength_count</strong>, <strong>current_count</strong> and <strong>remaining_count</strong>.'),
  ];
  if ($storageSettingMaxlengthField) {
    $form['textcount_status_message']['#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['textcount_status_message']['#states'] = [
      'invisible' => [
        ':input[name="fields[' . $this->fieldDefinition
          ->getName() . '][settings_edit_form][settings][maxlength]"]' => [
          'value' => 0,
        ],
      ],
    ];
  }
}