From 1bfb110559ed06c73b5ab0d67bcfd163074a0727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Kalij=C3=A4rvi?= Date: Mon, 4 Mar 2024 17:41:38 +0200 Subject: [PATCH 01/13] UHF-9690: Added field widgets for text field, text area and formatted text fields. --- ...ormatted_text_character_counter.schema.yml | 10 +++ .../textarea_character_counter.schema.yml | 10 +++ .../textfield_character_counter.schema.yml | 10 +++ .../FormattedTextCharacterCounterWidget.php | 74 +++++++++++++++++++ .../TextareaCharacterCounterWidget.php | 74 +++++++++++++++++++ .../TextfieldCharacterCounterWidget.php | 74 +++++++++++++++++++ 6 files changed, 252 insertions(+) create mode 100644 modules/hdbt_admin_tools/config/schema/formatted_text_character_counter.schema.yml create mode 100644 modules/hdbt_admin_tools/config/schema/textarea_character_counter.schema.yml create mode 100644 modules/hdbt_admin_tools/config/schema/textfield_character_counter.schema.yml create mode 100644 modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/FormattedTextCharacterCounterWidget.php create mode 100644 modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/TextareaCharacterCounterWidget.php create mode 100644 modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/TextfieldCharacterCounterWidget.php diff --git a/modules/hdbt_admin_tools/config/schema/formatted_text_character_counter.schema.yml b/modules/hdbt_admin_tools/config/schema/formatted_text_character_counter.schema.yml new file mode 100644 index 000000000..a2c28c4a8 --- /dev/null +++ b/modules/hdbt_admin_tools/config/schema/formatted_text_character_counter.schema.yml @@ -0,0 +1,10 @@ +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' diff --git a/modules/hdbt_admin_tools/config/schema/textarea_character_counter.schema.yml b/modules/hdbt_admin_tools/config/schema/textarea_character_counter.schema.yml new file mode 100644 index 000000000..d2813b662 --- /dev/null +++ b/modules/hdbt_admin_tools/config/schema/textarea_character_counter.schema.yml @@ -0,0 +1,10 @@ +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' diff --git a/modules/hdbt_admin_tools/config/schema/textfield_character_counter.schema.yml b/modules/hdbt_admin_tools/config/schema/textfield_character_counter.schema.yml new file mode 100644 index 000000000..cbee535ee --- /dev/null +++ b/modules/hdbt_admin_tools/config/schema/textfield_character_counter.schema.yml @@ -0,0 +1,10 @@ +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' diff --git a/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/FormattedTextCharacterCounterWidget.php b/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/FormattedTextCharacterCounterWidget.php new file mode 100644 index 000000000..8037be5cc --- /dev/null +++ b/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/FormattedTextCharacterCounterWidget.php @@ -0,0 +1,74 @@ + 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['#character_counter'] = TRUE; + $element['#counter_step'] = $this->getSetting('counter_step'); + $element['#counter_total'] = $this->getSetting('counter_total'); + return $element; + } + +} diff --git a/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/TextareaCharacterCounterWidget.php b/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/TextareaCharacterCounterWidget.php new file mode 100644 index 000000000..92cb86ab7 --- /dev/null +++ b/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/TextareaCharacterCounterWidget.php @@ -0,0 +1,74 @@ + 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; + } + +} diff --git a/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/TextfieldCharacterCounterWidget.php b/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/TextfieldCharacterCounterWidget.php new file mode 100644 index 000000000..f986226c4 --- /dev/null +++ b/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/TextfieldCharacterCounterWidget.php @@ -0,0 +1,74 @@ + 0, + 'counter_total' => 55, + ] + 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; + } + +} From 5aaef67bca277ed2d4033179d9e8a1aee9e31c6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Kalij=C3=A4rvi?= Date: Mon, 4 Mar 2024 17:42:55 +0200 Subject: [PATCH 02/13] UHF-9690: Added theme hook suggestion and preprocessing for the character counter form elements. Translated field widget texts. --- .../hdbt_admin_tools/hdbt_admin_tools.module | 23 +++++++++++++++++++ modules/hdbt_admin_tools/translations/fi.po | 9 ++++++++ 2 files changed, 32 insertions(+) diff --git a/modules/hdbt_admin_tools/hdbt_admin_tools.module b/modules/hdbt_admin_tools/hdbt_admin_tools.module index 3102305e7..fc822c829 100644 --- a/modules/hdbt_admin_tools/hdbt_admin_tools.module +++ b/modules/hdbt_admin_tools/hdbt_admin_tools.module @@ -1066,3 +1066,26 @@ function hdbt_admin_tools_entity_base_field_info_alter(&$fields) { $fields['langcode']->setDescription($translation); } } + +/** + * Implements hook_theme_suggestions_HOOK_alter(). + */ +function hdbt_admin_tools_theme_suggestions_form_element_alter(array &$suggestions, array $variables): void { + // Add character count suggestions to configured form elements. + if (isset($variables['element']['#character_counter'])) { + $suggestions[] = $variables['theme_hook_original'] . '__character_count'; + } +} + +/** + * Implements hook_preprocess_HOOK(). + */ +function hdbt_admin_tools_preprocess_form_element(array &$variables): void { + if (!isset($variables['element']['#character_counter'])) { + return; + } + // Set character counter values to variables. + $variables['counter_step'] = $variables['element']['#counter_step']; + $variables['counter_total'] = $variables['element']['#counter_total']; + $variables['counter_input_tag'] = $variables['element']['#type'] === 'textarea' ? 'textarea' : 'input'; +} diff --git a/modules/hdbt_admin_tools/translations/fi.po b/modules/hdbt_admin_tools/translations/fi.po index de1b8dd80..8ced6b156 100644 --- a/modules/hdbt_admin_tools/translations/fi.po +++ b/modules/hdbt_admin_tools/translations/fi.po @@ -129,3 +129,12 @@ msgstr "Hero-lohko on pakollinen jos Hero-lohko -valintaruutu on valittuna. Pois msgid "If you want to translate this page, do not change this value. You can translate this content from the 'Translate' -tab" msgstr "Jos haluat luoda tästä sivusta uuden käännöksen, älä vaihda tätä arvoa, vaan luo uusi käännös 'Käännä'-välilehdeltä" + +msgid "Text area (formatted text, character counter)" +msgstr "Tekstialue (muotoiltu, merkkimäärälaskuri)" + +msgid "Text area (character counter)" +msgstr "Tekstialue (merkkimäärälaskuri)" + +msgid "Textfield (character counter)" +msgstr "Tekstikenttä (merkkimäärälaskuri)" From b63ddcf331859323b2b5f4927f1f6b212c0a0ad6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Kalij=C3=A4rvi?= Date: Mon, 4 Mar 2024 17:44:32 +0200 Subject: [PATCH 03/13] UHF-9690: Applied character counter widgets to basic page title and lead in fields hero paragraph title and description fields. --- ....entity_form_display.node.page.default.yml | 8 ++++++-- ...ty_form_display.paragraph.hero.default.yml | 19 ++++++++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/modules/helfi_node_page/config/install/core.entity_form_display.node.page.default.yml b/modules/helfi_node_page/config/install/core.entity_form_display.node.page.default.yml index 98f08a707..75f9da539 100644 --- a/modules/helfi_node_page/config/install/core.entity_form_display.node.page.default.yml +++ b/modules/helfi_node_page/config/install/core.entity_form_display.node.page.default.yml @@ -76,10 +76,12 @@ content: duplicate: '0' third_party_settings: { } field_lead_in: - type: string_textarea + type: textarea_character_counter weight: 13 region: content settings: + counter_step: 160 + counter_total: 200 rows: 3 placeholder: '' third_party_settings: { } @@ -200,10 +202,12 @@ content: display_label: true third_party_settings: { } title: - type: string_textfield + type: textfield_character_counter weight: 1 region: content settings: + counter_step: 0 + counter_total: 55 size: 60 placeholder: '' third_party_settings: { } diff --git a/modules/helfi_paragraphs_hero/config/install/core.entity_form_display.paragraph.hero.default.yml b/modules/helfi_paragraphs_hero/config/install/core.entity_form_display.paragraph.hero.default.yml index f30ec32fd..f7f1b5068 100644 --- a/modules/helfi_paragraphs_hero/config/install/core.entity_form_display.paragraph.hero.default.yml +++ b/modules/helfi_paragraphs_hero/config/install/core.entity_form_display.paragraph.hero.default.yml @@ -10,22 +10,27 @@ dependencies: - field.field.paragraph.hero.field_hero_title - paragraphs.paragraphs_type.hero module: + - allowed_formats - hdbt_admin_tools - media_library - - text id: paragraph.hero.default targetEntityType: paragraph bundle: hero mode: default content: field_hero_desc: - type: text_textarea + type: formatted_text_character_counter weight: 3 region: content settings: - rows: 5 + counter_step: 160 + counter_total: 200 + rows: '5' placeholder: '' - third_party_settings: { } + third_party_settings: + allowed_formats: + hide_help: '0' + hide_guidelines: '0' field_hero_design: type: design_field_widget weight: 0 @@ -44,6 +49,8 @@ content: weight: 6 region: content settings: + placeholder_url: '' + placeholder_title: '' linkit_profile: helfi linkit_auto_link_text: false third_party_settings: { } @@ -54,10 +61,12 @@ content: settings: { } third_party_settings: { } field_hero_title: - type: string_textfield + type: textfield_character_counter weight: 2 region: content settings: + counter_step: 0 + counter_total: 55 size: 60 placeholder: '' third_party_settings: { } From aa593e03866e49ba3932750e1efd56d14d759d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Kalij=C3=A4rvi?= Date: Mon, 4 Mar 2024 17:52:58 +0200 Subject: [PATCH 04/13] UHF-9690: Added update hooks. --- modules/helfi_node_page/helfi_node_page.install | 4 ++-- .../helfi_paragraphs_hero/helfi_paragraphs_hero.install | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/modules/helfi_node_page/helfi_node_page.install b/modules/helfi_node_page/helfi_node_page.install index 1e39ba087..f580cf810 100644 --- a/modules/helfi_node_page/helfi_node_page.install +++ b/modules/helfi_node_page/helfi_node_page.install @@ -104,9 +104,9 @@ function helfi_node_page_update_9001() : void { } /** - * Set node as unpublished on default. + * UHF-9690 Added character counter to title and lead in. */ -function helfi_node_page_update_9002() : void { +function helfi_node_page_update_9003() : void { // Re-import configuration. \Drupal::service('helfi_platform_config.config_update_helper') ->update('helfi_node_page'); diff --git a/modules/helfi_paragraphs_hero/helfi_paragraphs_hero.install b/modules/helfi_paragraphs_hero/helfi_paragraphs_hero.install index 09ff14cb2..2702c41be 100644 --- a/modules/helfi_paragraphs_hero/helfi_paragraphs_hero.install +++ b/modules/helfi_paragraphs_hero/helfi_paragraphs_hero.install @@ -34,3 +34,12 @@ function helfi_paragraphs_hero_update_9003(): void { // values with allowed_values_function. } } + +/** + * UHF-9690 Added character counter to hero title and hero description. + */ +function helfi_paragraphs_hero_update_9004() : void { + // Re-import configuration. + \Drupal::service('helfi_platform_config.config_update_helper') + ->update('helfi_paragraphs_hero'); +} From f0914dde76d9038a7e9ec045df4dd64690f5b1b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Kalij=C3=A4rvi?= Date: Mon, 4 Mar 2024 18:29:23 +0200 Subject: [PATCH 05/13] UHF-9690: Use CharacterCounterFieldWidgetTrait. --- .../CharacterCounterFieldWidgetTrait.php | 66 +++++++++++++++++++ .../FormattedTextCharacterCounterWidget.php | 40 +---------- .../TextareaCharacterCounterWidget.php | 52 +-------------- .../TextfieldCharacterCounterWidget.php | 44 +------------ 4 files changed, 72 insertions(+), 130 deletions(-) create mode 100644 modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/CharacterCounterFieldWidgetTrait.php diff --git a/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/CharacterCounterFieldWidgetTrait.php b/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/CharacterCounterFieldWidgetTrait.php new file mode 100644 index 000000000..1982ec13b --- /dev/null +++ b/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/CharacterCounterFieldWidgetTrait.php @@ -0,0 +1,66 @@ + 0, + 'counter_total' => 55, + ] + 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; + } + +} diff --git a/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/FormattedTextCharacterCounterWidget.php b/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/FormattedTextCharacterCounterWidget.php index 8037be5cc..71c7bf4b1 100644 --- a/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/FormattedTextCharacterCounterWidget.php +++ b/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/FormattedTextCharacterCounterWidget.php @@ -7,6 +7,7 @@ use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\text\Plugin\Field\FieldWidget\TextareaWidget; +use Drupal\hdbt_admin_tools\Plugin\Field\FieldWidget\CharacterCounterTraitFieldWidget; /** * Plugin implementation of the 'formatted_text_character_counter' widget. @@ -21,45 +22,8 @@ */ class FormattedTextCharacterCounterWidget extends TextareaWidget { - /** - * {@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; - } + use CharacterCounterFieldWidgetTrait; - /** - * {@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} */ diff --git a/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/TextareaCharacterCounterWidget.php b/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/TextareaCharacterCounterWidget.php index 92cb86ab7..fc015dea4 100644 --- a/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/TextareaCharacterCounterWidget.php +++ b/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/TextareaCharacterCounterWidget.php @@ -4,9 +4,7 @@ namespace Drupal\hdbt_admin_tools\Plugin\Field\FieldWidget; -use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\Plugin\Field\FieldWidget\StringTextareaWidget; -use Drupal\Core\Form\FormStateInterface; /** * Plugin implementation of the 'textarea_character_counter' widget. @@ -21,54 +19,6 @@ */ class TextareaCharacterCounterWidget extends StringTextareaWidget { - /** - * {@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; - } + use CharacterCounterFieldWidgetTrait; } diff --git a/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/TextfieldCharacterCounterWidget.php b/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/TextfieldCharacterCounterWidget.php index f986226c4..ca39de2b0 100644 --- a/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/TextfieldCharacterCounterWidget.php +++ b/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/TextfieldCharacterCounterWidget.php @@ -19,7 +19,9 @@ * } * ) */ -class TextFieldCharacterCounterWidget extends StringTextfieldWidget { +class TextfieldCharacterCounterWidget extends StringTextfieldWidget { + + use CharacterCounterFieldWidgetTrait; /** * {@inheritdoc} @@ -31,44 +33,4 @@ public static function defaultSettings(): array { ] + 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; - } - } From 5fa1ad4a644f0ae3ed278529c8de9f34e6f8acdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Kalij=C3=A4rvi?= Date: Mon, 4 Mar 2024 18:34:31 +0200 Subject: [PATCH 06/13] UHF-9690: Fixed phpcs errors. --- .../Field/FieldWidget/FormattedTextCharacterCounterWidget.php | 1 - .../Field/FieldWidget/TextfieldCharacterCounterWidget.php | 2 -- 2 files changed, 3 deletions(-) diff --git a/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/FormattedTextCharacterCounterWidget.php b/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/FormattedTextCharacterCounterWidget.php index 71c7bf4b1..30a37b78d 100644 --- a/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/FormattedTextCharacterCounterWidget.php +++ b/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/FormattedTextCharacterCounterWidget.php @@ -7,7 +7,6 @@ use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\text\Plugin\Field\FieldWidget\TextareaWidget; -use Drupal\hdbt_admin_tools\Plugin\Field\FieldWidget\CharacterCounterTraitFieldWidget; /** * Plugin implementation of the 'formatted_text_character_counter' widget. diff --git a/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/TextfieldCharacterCounterWidget.php b/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/TextfieldCharacterCounterWidget.php index ca39de2b0..fecba0667 100644 --- a/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/TextfieldCharacterCounterWidget.php +++ b/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/TextfieldCharacterCounterWidget.php @@ -4,9 +4,7 @@ namespace Drupal\hdbt_admin_tools\Plugin\Field\FieldWidget; -use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\Plugin\Field\FieldWidget\StringTextfieldWidget; -use Drupal\Core\Form\FormStateInterface; /** * Plugin implementation of the 'textarea_character_counter' widget. From b06c4757c3e946677d74218afb62f238aeff584d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Kalij=C3=A4rvi?= Date: Mon, 4 Mar 2024 18:37:43 +0200 Subject: [PATCH 07/13] UHF-9690: Catch the field storage definition error. --- modules/helfi_ckeditor/helfi_ckeditor.install | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/modules/helfi_ckeditor/helfi_ckeditor.install b/modules/helfi_ckeditor/helfi_ckeditor.install index dafc2dc1c..312cc05cc 100644 --- a/modules/helfi_ckeditor/helfi_ckeditor.install +++ b/modules/helfi_ckeditor/helfi_ckeditor.install @@ -7,6 +7,8 @@ declare(strict_types=1); +use Drupal\Core\Entity\Exception\FieldStorageDefinitionUpdateForbiddenException; + /** * Grants required permissions. */ @@ -273,6 +275,13 @@ function helfi_ckeditor_update_9007(): void { * UHF-9497 Added missing figcaption and figure elements. */ function helfi_ckeditor_update_9008(): void { - \Drupal::service('helfi_platform_config.config_update_helper') - ->update('helfi_ckeditor'); + try { + \Drupal::service('helfi_platform_config.config_update_helper') + ->update('helfi_ckeditor'); + } + catch (FieldStorageDefinitionUpdateForbiddenException $exception) { + // We know the database values are different what we are trying + // to write there, but we are only replacing the + // values with allowed_values_function. + } } From d00dadc6523b347572871780651b929ab04a0978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Kalij=C3=A4rvi?= Date: Mon, 4 Mar 2024 18:42:57 +0200 Subject: [PATCH 08/13] UHF-9690: Catch the error from correct function. --- modules/helfi_ckeditor/helfi_ckeditor.install | 13 ++----------- .../helfi_paragraphs_hero.install | 12 +++++++++--- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/modules/helfi_ckeditor/helfi_ckeditor.install b/modules/helfi_ckeditor/helfi_ckeditor.install index 312cc05cc..dafc2dc1c 100644 --- a/modules/helfi_ckeditor/helfi_ckeditor.install +++ b/modules/helfi_ckeditor/helfi_ckeditor.install @@ -7,8 +7,6 @@ declare(strict_types=1); -use Drupal\Core\Entity\Exception\FieldStorageDefinitionUpdateForbiddenException; - /** * Grants required permissions. */ @@ -275,13 +273,6 @@ function helfi_ckeditor_update_9007(): void { * UHF-9497 Added missing figcaption and figure elements. */ function helfi_ckeditor_update_9008(): void { - try { - \Drupal::service('helfi_platform_config.config_update_helper') - ->update('helfi_ckeditor'); - } - catch (FieldStorageDefinitionUpdateForbiddenException $exception) { - // We know the database values are different what we are trying - // to write there, but we are only replacing the - // values with allowed_values_function. - } + \Drupal::service('helfi_platform_config.config_update_helper') + ->update('helfi_ckeditor'); } diff --git a/modules/helfi_paragraphs_hero/helfi_paragraphs_hero.install b/modules/helfi_paragraphs_hero/helfi_paragraphs_hero.install index 2702c41be..0b784e72c 100644 --- a/modules/helfi_paragraphs_hero/helfi_paragraphs_hero.install +++ b/modules/helfi_paragraphs_hero/helfi_paragraphs_hero.install @@ -39,7 +39,13 @@ function helfi_paragraphs_hero_update_9003(): void { * UHF-9690 Added character counter to hero title and hero description. */ function helfi_paragraphs_hero_update_9004() : void { - // Re-import configuration. - \Drupal::service('helfi_platform_config.config_update_helper') - ->update('helfi_paragraphs_hero'); + try { + \Drupal::service('helfi_platform_config.config_update_helper') + ->update('helfi_paragraphs_hero'); + } + catch (FieldStorageDefinitionUpdateForbiddenException $exception) { + // We know the database values are different what we are trying + // to write there, but we are only replacing the + // values with allowed_values_function. + } } From 89cc3f1fd9ce87006e022ce2170b33185dbec70d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Kalij=C3=A4rvi?= Date: Mon, 4 Mar 2024 18:48:33 +0200 Subject: [PATCH 09/13] UHF-9690: Added missing schemas. --- .../schema/formatted_text_character_counter.schema.yml | 6 ++++++ .../config/schema/textarea_character_counter.schema.yml | 6 ++++++ .../config/schema/textfield_character_counter.schema.yml | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/modules/hdbt_admin_tools/config/schema/formatted_text_character_counter.schema.yml b/modules/hdbt_admin_tools/config/schema/formatted_text_character_counter.schema.yml index a2c28c4a8..401ea56a9 100644 --- a/modules/hdbt_admin_tools/config/schema/formatted_text_character_counter.schema.yml +++ b/modules/hdbt_admin_tools/config/schema/formatted_text_character_counter.schema.yml @@ -8,3 +8,9 @@ field.widget.settings.formatted_text_character_counter: counter_total: type: integer label: 'Counter total' + rows: + type: integer + label: 'Rows' + placeholder: + type: label + label: 'Placeholder' diff --git a/modules/hdbt_admin_tools/config/schema/textarea_character_counter.schema.yml b/modules/hdbt_admin_tools/config/schema/textarea_character_counter.schema.yml index d2813b662..6ea158b76 100644 --- a/modules/hdbt_admin_tools/config/schema/textarea_character_counter.schema.yml +++ b/modules/hdbt_admin_tools/config/schema/textarea_character_counter.schema.yml @@ -8,3 +8,9 @@ field.widget.settings.textarea_character_counter: counter_total: type: integer label: 'Counter total' + rows: + type: integer + label: 'Rows' + placeholder: + type: label + label: 'Placeholder' diff --git a/modules/hdbt_admin_tools/config/schema/textfield_character_counter.schema.yml b/modules/hdbt_admin_tools/config/schema/textfield_character_counter.schema.yml index cbee535ee..5b736d764 100644 --- a/modules/hdbt_admin_tools/config/schema/textfield_character_counter.schema.yml +++ b/modules/hdbt_admin_tools/config/schema/textfield_character_counter.schema.yml @@ -8,3 +8,9 @@ field.widget.settings.textfield_character_counter: counter_total: type: integer label: 'Counter total' + size: + type: integer + label: 'Size of textfield' + placeholder: + type: label + label: 'Placeholder' From 077789ff9cf93d08c7680a09e7ebbcb0bd8353aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Kalij=C3=A4rvi?= Date: Mon, 4 Mar 2024 18:56:29 +0200 Subject: [PATCH 10/13] UHF-9690: Fixed the default counter values. --- .../Field/FieldWidget/CharacterCounterFieldWidgetTrait.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/CharacterCounterFieldWidgetTrait.php b/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/CharacterCounterFieldWidgetTrait.php index 1982ec13b..a222626f1 100644 --- a/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/CharacterCounterFieldWidgetTrait.php +++ b/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/CharacterCounterFieldWidgetTrait.php @@ -17,8 +17,8 @@ trait CharacterCounterFieldWidgetTrait { */ public static function defaultSettings(): array { return [ - 'counter_step' => 0, - 'counter_total' => 55, + 'counter_step' => 160, + 'counter_total' => 200, ] + parent::defaultSettings(); } From 63c56eac01e92d917126119958b953e07393c6be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Kalij=C3=A4rvi?= Date: Mon, 4 Mar 2024 19:14:06 +0200 Subject: [PATCH 11/13] UHF-9690: Fixed hero paragraph configuration. --- .../install/core.entity_form_display.paragraph.hero.default.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/helfi_paragraphs_hero/config/install/core.entity_form_display.paragraph.hero.default.yml b/modules/helfi_paragraphs_hero/config/install/core.entity_form_display.paragraph.hero.default.yml index f7f1b5068..0dbc041ab 100644 --- a/modules/helfi_paragraphs_hero/config/install/core.entity_form_display.paragraph.hero.default.yml +++ b/modules/helfi_paragraphs_hero/config/install/core.entity_form_display.paragraph.hero.default.yml @@ -25,7 +25,7 @@ content: settings: counter_step: 160 counter_total: 200 - rows: '5' + rows: 5 placeholder: '' third_party_settings: allowed_formats: From 99003bee7047c5cca19bfb327fa3e98792e573fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Kalij=C3=A4rvi?= Date: Tue, 5 Mar 2024 09:12:31 +0200 Subject: [PATCH 12/13] UHF-9690: Added patch to fix switching from allowed values list to allowed values function. --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e0df5e9c7..4ce2243f7 100644 --- a/composer.json +++ b/composer.json @@ -82,7 +82,8 @@ "[#UHF-7008] Core localization file download URL is wrong (https://www.drupal.org/project/drupal/issues/3022876)": "https://git.drupalcode.org/project/drupal/-/commit/40a96136b2dfe4322338508dffa636f6cb407900.patch", "[#UHF-7008] Add multilingual support for caching basefield definitions (https://www.drupal.org/project/drupal/issues/3114824)": "https://www.drupal.org/files/issues/2020-02-20/3114824_2.patch", "[#UHF-7008] Admin toolbar and contextual links should always be rendered in the admin language (https://www.drupal.org/project/drupal/issues/2313309)": "https://www.drupal.org/files/issues/2023-12-19/2313309-179.patch", - "[#UHF-9388] Process translation config files for custom modules (https://www.drupal.org/i/2845437)": "https://www.drupal.org/files/issues/2023-10-16/2845437-61.patch" + "[#UHF-9388] Process translation config files for custom modules (https://www.drupal.org/i/2845437)": "https://www.drupal.org/files/issues/2023-10-16/2845437-61.patch", + "[#UHF-9690] Allow updating lists when switching from allowed values to allowed values function (https://www.drupal.org/i/2873353)": "https://www.drupal.org/files/issues/2021-05-18/allow-allowed-values-function-update-D9-2873353_1.patch" }, "drupal/default_content": { "https://www.drupal.org/project/default_content/issues/2640734#comment-14638943": "https://raw.githubusercontent.com/City-of-Helsinki/drupal-helfi-platform-config/main/patches/default_content_2.0.0-alpha2-2640734_manual_imports-e164a354.patch" From 3af935bc08f57fe9dc39870c844b7ed07f30991b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Kalij=C3=A4rvi?= Date: Tue, 5 Mar 2024 09:45:29 +0200 Subject: [PATCH 13/13] UHF-9690: Translated hero paragraph design values with t() as the allowed values function is in use. --- ...ield.storage.paragraph.field_hero_design.yml | 12 ------------ ...ield.storage.paragraph.field_hero_design.yml | 12 ------------ .../helfi_paragraphs_hero.info.yml | 2 ++ .../helfi_paragraphs_hero/translations/fi.po | 17 +++++++++++++++++ .../helfi_paragraphs_hero/translations/sv.po | 17 +++++++++++++++++ 5 files changed, 36 insertions(+), 24 deletions(-) delete mode 100644 modules/helfi_paragraphs_hero/config/optional/language/fi/field.storage.paragraph.field_hero_design.yml delete mode 100644 modules/helfi_paragraphs_hero/config/optional/language/sv/field.storage.paragraph.field_hero_design.yml create mode 100644 modules/helfi_paragraphs_hero/translations/fi.po create mode 100644 modules/helfi_paragraphs_hero/translations/sv.po diff --git a/modules/helfi_paragraphs_hero/config/optional/language/fi/field.storage.paragraph.field_hero_design.yml b/modules/helfi_paragraphs_hero/config/optional/language/fi/field.storage.paragraph.field_hero_design.yml deleted file mode 100644 index 7e625c9ce..000000000 --- a/modules/helfi_paragraphs_hero/config/optional/language/fi/field.storage.paragraph.field_hero_design.yml +++ /dev/null @@ -1,12 +0,0 @@ -settings: - allowed_values: - - - label: 'Ilman kuvaa, tasattu vasemmalle' - - - label: 'Kuva oikealla' - - - label: 'Kuva vasemmalla' - - - label: 'Kuva alhaalla' - - - label: Diagonaalinen diff --git a/modules/helfi_paragraphs_hero/config/optional/language/sv/field.storage.paragraph.field_hero_design.yml b/modules/helfi_paragraphs_hero/config/optional/language/sv/field.storage.paragraph.field_hero_design.yml deleted file mode 100644 index 5c5f4ec15..000000000 --- a/modules/helfi_paragraphs_hero/config/optional/language/sv/field.storage.paragraph.field_hero_design.yml +++ /dev/null @@ -1,12 +0,0 @@ -settings: - allowed_values: - - - label: 'Utan bild, justerad vänster' - - - label: 'Bild justerad till höger' - - - label: 'Bild justerad till vänster' - - - label: 'Bild justerad ner' - - - label: Diagonal diff --git a/modules/helfi_paragraphs_hero/helfi_paragraphs_hero.info.yml b/modules/helfi_paragraphs_hero/helfi_paragraphs_hero.info.yml index eed833957..5681c8c77 100644 --- a/modules/helfi_paragraphs_hero/helfi_paragraphs_hero.info.yml +++ b/modules/helfi_paragraphs_hero/helfi_paragraphs_hero.info.yml @@ -12,3 +12,5 @@ dependencies: - helfi_base_content:helfi_base_content - helfi_image_styles:helfi_image_styles - helfi_media:helfi_media +'interface translation project': helfi_paragraphs_hero +'interface translation server pattern': modules/contrib/helfi_platform_config/modules/helfi_paragraphs_hero/translations/%language.po diff --git a/modules/helfi_paragraphs_hero/translations/fi.po b/modules/helfi_paragraphs_hero/translations/fi.po new file mode 100644 index 000000000..5837811a6 --- /dev/null +++ b/modules/helfi_paragraphs_hero/translations/fi.po @@ -0,0 +1,17 @@ +msgid "" +msgstr "" + +msgid "Without image, align left" +msgstr "Ilman kuvaa, tasattu vasemmalle" + +msgid "Image on the right" +msgstr "Kuva oikealla" + +msgid "Image on the left" +msgstr "Kuva vasemmalla" + +msgid "Image on the bottom" +msgstr "Kuva alhaalla" + +msgid "Diagonal" +msgstr "Diagonaalinen" diff --git a/modules/helfi_paragraphs_hero/translations/sv.po b/modules/helfi_paragraphs_hero/translations/sv.po new file mode 100644 index 000000000..a8e890d05 --- /dev/null +++ b/modules/helfi_paragraphs_hero/translations/sv.po @@ -0,0 +1,17 @@ +msgid "" +msgstr "" + +msgid "Without image, align left" +msgstr "Utan bild, justerad vänster" + +msgid "Image on the right" +msgstr "Bild justerad till höger" + +msgid "Image on the left" +msgstr "Bild justerad till vänster" + +msgid "Image on the bottom" +msgstr "Bild justerad ner" + +msgid "Diagonal" +msgstr "Diagonal"