public function TextFieldCounterWidgetTrait::addCountHtmlSettingsFormElement in Textfield Counter 8
Adds a form element to determine whether HTML characters should be counted.
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::addCountHtmlSettingsFormElement()
- 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 142
Class
- TextFieldCounterWidgetTrait
- Textfield counter trait. Adds textfield counting functionality.
Namespace
Drupal\textfield_counter\Plugin\Field\FieldWidgetCode
public function addCountHtmlSettingsFormElement(array &$form, $storageSettingMaxlengthField = FALSE) {
$form['count_html_characters'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Include HTML characters in the character count'),
'#description' => $this
->t('When this box is checked, HTML characters are included in the character count. For example, when this box is checked, the string <em><p>Hi</p></em> would be nine characters long. When this box is not checked, the character count would be two characters long (for hi). Note that if this textarea uses an editor like CKEditor, it is very likely that this box should be unchecked.'),
'#default_value' => $this
->getSetting('count_html_characters'),
];
if ($storageSettingMaxlengthField) {
$form['count_html_characters']['#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['count_html_characters']['#states'] = [
'invisible' => [
':input[name="fields[' . $this->fieldDefinition
->getName() . '][settings_edit_form][settings][maxlength]"]' => [
'value' => 0,
],
],
];
}
}