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" 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..401ea56a9 --- /dev/null +++ b/modules/hdbt_admin_tools/config/schema/formatted_text_character_counter.schema.yml @@ -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' 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..6ea158b76 --- /dev/null +++ b/modules/hdbt_admin_tools/config/schema/textarea_character_counter.schema.yml @@ -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' 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..5b736d764 --- /dev/null +++ b/modules/hdbt_admin_tools/config/schema/textfield_character_counter.schema.yml @@ -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' 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/src/Plugin/Field/FieldWidget/CharacterCounterFieldWidgetTrait.php b/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/CharacterCounterFieldWidgetTrait.php new file mode 100644 index 000000000..a222626f1 --- /dev/null +++ b/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/CharacterCounterFieldWidgetTrait.php @@ -0,0 +1,66 @@ + 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/FormattedTextCharacterCounterWidget.php b/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/FormattedTextCharacterCounterWidget.php new file mode 100644 index 000000000..30a37b78d --- /dev/null +++ b/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/FormattedTextCharacterCounterWidget.php @@ -0,0 +1,37 @@ +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..fc015dea4 --- /dev/null +++ b/modules/hdbt_admin_tools/src/Plugin/Field/FieldWidget/TextareaCharacterCounterWidget.php @@ -0,0 +1,24 @@ + 0, + 'counter_total' => 55, + ] + parent::defaultSettings(); + } + +} 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)" 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_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/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..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 @@ -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: + 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: { } diff --git a/modules/helfi_paragraphs_hero/helfi_paragraphs_hero.install b/modules/helfi_paragraphs_hero/helfi_paragraphs_hero.install index 09ff14cb2..0b784e72c 100644 --- a/modules/helfi_paragraphs_hero/helfi_paragraphs_hero.install +++ b/modules/helfi_paragraphs_hero/helfi_paragraphs_hero.install @@ -34,3 +34,18 @@ 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 { + 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. + } +}