-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
279 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
modules/hdbt_admin_tools/config/schema/formatted_text_character_counter.schema.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
field.widget.settings.formatted_text_character_counter: | ||
type: mapping | ||
label: 'Character counter formatted text widget display format settings' | ||
mapping: | ||
counter_step: | ||
type: integer | ||
label: 'Counter step' | ||
counter_total: | ||
type: integer | ||
label: 'Counter total' | ||
rows: | ||
type: integer | ||
label: 'Rows' | ||
placeholder: | ||
type: label | ||
label: 'Placeholder' |
16 changes: 16 additions & 0 deletions
16
modules/hdbt_admin_tools/config/schema/textarea_character_counter.schema.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
field.widget.settings.textarea_character_counter: | ||
type: mapping | ||
label: 'Character counter text area widget display format settings' | ||
mapping: | ||
counter_step: | ||
type: integer | ||
label: 'Counter step' | ||
counter_total: | ||
type: integer | ||
label: 'Counter total' | ||
rows: | ||
type: integer | ||
label: 'Rows' | ||
placeholder: | ||
type: label | ||
label: 'Placeholder' |
16 changes: 16 additions & 0 deletions
16
modules/hdbt_admin_tools/config/schema/textfield_character_counter.schema.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
field.widget.settings.textfield_character_counter: | ||
type: mapping | ||
label: 'Character counter textfield widget display format settings' | ||
mapping: | ||
counter_step: | ||
type: integer | ||
label: 'Counter step' | ||
counter_total: | ||
type: integer | ||
label: 'Counter total' | ||
size: | ||
type: integer | ||
label: 'Size of textfield' | ||
placeholder: | ||
type: label | ||
label: 'Placeholder' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/CharacterCounterFieldWidgetTrait.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\hdbt_admin_tools\Plugin\Field\FieldWidget; | ||
|
||
use Drupal\Core\Field\FieldItemListInterface; | ||
use Drupal\Core\Form\FormStateInterface; | ||
|
||
/** | ||
* Trait for handling character counter settings and form elements. | ||
*/ | ||
trait CharacterCounterFieldWidgetTrait { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function defaultSettings(): array { | ||
return [ | ||
'counter_step' => 160, | ||
'counter_total' => 200, | ||
] + parent::defaultSettings(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function settingsForm(array $form, FormStateInterface $form_state): array { | ||
$element = parent::settingsForm($form, $form_state); | ||
$element['counter_step'] = [ | ||
'#type' => 'number', | ||
'#title' => $this->t('Suggestion text character count'), | ||
'#default_value' => $this->getSetting('counter_step'), | ||
'#required' => TRUE, | ||
]; | ||
$element['counter_total'] = [ | ||
'#type' => 'number', | ||
'#title' => $this->t('Warning text character count'), | ||
'#default_value' => $this->getSetting('counter_total'), | ||
'#required' => TRUE, | ||
]; | ||
return $element; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function settingsSummary(): array { | ||
$summary = parent::settingsSummary(); | ||
$summary[] = $this->t('Suggestion text character count: @count', ['@count' => $this->getSetting('counter_step')]); | ||
$summary[] = $this->t('Warning text character count: @count', ['@count' => $this->getSetting('counter_total')]); | ||
return $summary; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state): array { | ||
$element = parent::formElement($items, $delta, $element, $form, $form_state); | ||
$element['value']['#character_counter'] = TRUE; | ||
$element['value']['#counter_step'] = $this->getSetting('counter_step'); | ||
$element['value']['#counter_total'] = $this->getSetting('counter_total'); | ||
return $element; | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
...les/hdbt_admin_tools/src/Plugin/Field/FieldWidget/FormattedTextCharacterCounterWidget.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\hdbt_admin_tools\Plugin\Field\FieldWidget; | ||
|
||
use Drupal\Core\Field\FieldItemListInterface; | ||
use Drupal\Core\Form\FormStateInterface; | ||
use Drupal\text\Plugin\Field\FieldWidget\TextareaWidget; | ||
|
||
/** | ||
* Plugin implementation of the 'formatted_text_character_counter' widget. | ||
* | ||
* @FieldWidget( | ||
* id = "formatted_text_character_counter", | ||
* label = @Translation("Text area (formatted text, character counter)"), | ||
* field_types = { | ||
* "text_long", | ||
* } | ||
* ) | ||
*/ | ||
class FormattedTextCharacterCounterWidget extends TextareaWidget { | ||
|
||
use CharacterCounterFieldWidgetTrait; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state): array { | ||
$element = parent::formElement($items, $delta, $element, $form, $form_state); | ||
$element['#character_counter'] = TRUE; | ||
$element['#counter_step'] = $this->getSetting('counter_step'); | ||
$element['#counter_total'] = $this->getSetting('counter_total'); | ||
return $element; | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/TextareaCharacterCounterWidget.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\hdbt_admin_tools\Plugin\Field\FieldWidget; | ||
|
||
use Drupal\Core\Field\Plugin\Field\FieldWidget\StringTextareaWidget; | ||
|
||
/** | ||
* Plugin implementation of the 'textarea_character_counter' widget. | ||
* | ||
* @FieldWidget( | ||
* id = "textarea_character_counter", | ||
* label = @Translation("Text area (character counter)"), | ||
* field_types = { | ||
* "string_long", | ||
* } | ||
* ) | ||
*/ | ||
class TextareaCharacterCounterWidget extends StringTextareaWidget { | ||
|
||
use CharacterCounterFieldWidgetTrait; | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/TextfieldCharacterCounterWidget.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\hdbt_admin_tools\Plugin\Field\FieldWidget; | ||
|
||
use Drupal\Core\Field\Plugin\Field\FieldWidget\StringTextfieldWidget; | ||
|
||
/** | ||
* Plugin implementation of the 'textarea_character_counter' widget. | ||
* | ||
* @FieldWidget( | ||
* id = "textfield_character_counter", | ||
* label = @Translation("Textfield (character counter)"), | ||
* field_types = { | ||
* "string" | ||
* } | ||
* ) | ||
*/ | ||
class TextfieldCharacterCounterWidget extends StringTextfieldWidget { | ||
|
||
use CharacterCounterFieldWidgetTrait; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function defaultSettings(): array { | ||
return [ | ||
'counter_step' => 0, | ||
'counter_total' => 55, | ||
] + parent::defaultSettings(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters