Add validation constraint to `type: label`: disallow multiple lines

Created on 26 July 2023, over 1 year ago
Updated 1 August 2023, over 1 year ago

Problem/Motivation

๐Ÿ“Œ New config schema data type: `required_label` Fixed tried to add validation to type: label. But it did so in a very broad way: disallow empty strings. That turned out to not be viable. So instead, it pivoted to introducing a new configuration schema data type: required_label.

(So it is essentially an alias of the label type with a NotBlank constraint sprinkled on top.)

While wrapping up that issue, I realized that there actually is sensible validation we could add to type: label too: disallowing multiple lines โ€” i.e. disallow \n and \r. That validation constraint would then be inherited by type: required_label too.

As a side benefit, this should surface (in combination with ๐Ÿ“Œ KernelTestBase::$strictConfigSchema = TRUE and BrowserTestBase::$strictConfigSchema = TRUE do not actually strictly validate Fixed which uses of type: label should really be type: text.

Steps to reproduce

Observe that:

  1. contact.form.*:message
  2. field.widget.settings.text_textarea_with_summary:placeholder

all use type: label but really allow multiple lines of text โ€” none of these are labels, they're just translatable multi-line strings.

Proposed resolution

Add RegEx validation constraint to type: label.

Remaining tasks

  1. Create merge request here that adds RegEx validation constraint to type: label
  2. Convert that MR into a patch that is applied on top of ๐Ÿ“Œ KernelTestBase::$strictConfigSchema = TRUE and BrowserTestBase::$strictConfigSchema = TRUE do not actually strictly validate Fixed (or better yet, hopefully that will land soonโ€ฆ) to allow detecting where all the incorrect uses of type: label are that should really be type: text.
  3. At a minimum, we'd expect failures for contact forms, menus and vocabularies (see "Steps to Reproduce")

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

None.

๐Ÿ“Œ Task
Status

Fixed

Version

11.0 ๐Ÿ”ฅ

Component
Configurationย  โ†’

Last updated 3 days ago

Created by

๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @wim leers
  • Open on Drupal.org โ†’
    Environment: PHP 8.2 & MySQL 8
    last update over 1 year ago
    Not currently mergeable.
  • @wim-leers opened merge request.
  • Assigned to wim leers
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Now that ๐Ÿ“Œ KernelTestBase::$strictConfigSchema = TRUE and BrowserTestBase::$strictConfigSchema = TRUE do not actually strictly validate Fixed is in, we'd be able to instantly see how much effect this would have. Let's find out!

  • last update over 1 year ago
    24,977 pass
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Wow, zero violations, really?! Maybe the violations only occur in functional tests? ๐Ÿค”

    Verified again locally that this indeed works correctly by changing core/profiles/standard/config/install/taxonomy.vocabulary.tags.yml to have a multi-line description and running StandardTest. Fails as expected ๐Ÿ‘

    So let's:

    1. Add explicit test coverage.
    2. Run the full test suite again.
  • last update over 1 year ago
    24,892 pass, 12 fail
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ
  • last update over 1 year ago
    25,008 pass
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium borisson_ Mechelen, ๐Ÿ‡ง๐Ÿ‡ช

    This needs another rebase it seems. Very suprised that only a few things in core were giving errors on this. Not sure if all the tests have ran on the last time, there is a change in drupalci.yml that needs to be undone.

  • Assigned to wim leers
  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Oops, yes, I forgot about that ๐Ÿ™ˆ Done! Probably hundreds of test failures now ๐Ÿ˜„

  • last update over 1 year ago
    29,916 pass
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Well well โ€ฆ I guess almost nothing in Drupal core uses a multi-line label!

    I really thought at least some contact form would trigger this, or a vocabulary description, or a menu description โ€ฆ but no! ๐Ÿ˜ฎ

    And sure enough, e.g. core/profiles/demo_umami/config/install/contact.form.feedback.yml uses a single line!

  • Status changed to RTBC over 1 year ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium borisson_ Mechelen, ๐Ÿ‡ง๐Ÿ‡ช

    This looks great, even better that nothing fails but we still improve strictness.

  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ซ๐Ÿ‡ฎFinland lauriii Finland

    Shouldn't we remove the incorrect uses of type: label mentioned in the issue summary (or at least have a follow-up to do that)? The UIs for these certainly would enable creating invalid config at the moment.

  • last update over 1 year ago
    29,905 pass, 2 fail
  • last update over 1 year ago
    29,945 pass
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    #10: works for me!

    Turns out that taxonomy.vocabulary.*:description's UI actually does not allow multiple lines. So I'm wrong about that one. ๐Ÿ™ˆ
    Same for system.menu.*:description! ๐Ÿ™ˆ
    Both of these are apparently used in listing UIs and that's why they only allow a single line.

    I am right about contact.form.*:message though. And I managed to find one more: field.widget.settings.text_textarea_with_summary:placeholder.

    Since there are so few examples: let's fix them here? First pushed failing test coverage, then the fix (i.e. tweaking config schema).

  • Status changed to RTBC over 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Change looks good and appears all green.

    Question though is if changing to text does that mean it can be translated?

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Question though is if changing to text does that mean it can be translated?

    Both type: label and type: text are translatable already:

    # Human readable string that must be plain text and editable with a text field.
    label:
      type: string
      label: 'Label'
      translatable: true
    
    โ€ฆ
    # Human readable string that can contain multiple lines of text or HTML.
    text:
      type: string
      label: 'Text'
      translatable: true
    

    โ€” core.data_types.schema.yml

    and:

    function config_translation_config_schema_info_alter(&$definitions) {
      $map = [
        'label' => '\Drupal\config_translation\FormElement\Textfield',
        'text' => '\Drupal\config_translation\FormElement\Textarea',
        'date_format' => '\Drupal\config_translation\FormElement\DateFormat',
        'text_format' => '\Drupal\config_translation\FormElement\TextFormat',
        'mapping' => '\Drupal\config_translation\FormElement\ListElement',
        'sequence' => '\Drupal\config_translation\FormElement\ListElement',
        'plural_label' => '\Drupal\config_translation\FormElement\PluralVariants',
      ];
    

    ๐Ÿ‘๐Ÿ˜Š

  • ๐Ÿ‡ซ๐Ÿ‡ฎFinland lauriii Finland

    Committed b7ee3dc and pushed to 11.x. Thanks!

  • Status changed to Fixed over 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024