Skip to content
Snippets Groups Projects

Issue #3395555: 🦺 add constraint configuration for...

Open Issue #3395555: 🦺 add constraint configuration for...
4 unresolved threads
4 unresolved threads

Issue #3395555: 🦺 add constraint configuration for olivero.settings.site_branding_bg_color, using Choice to limit to default, white, and gray.

Closes #3395555

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Joris Vercammen
  • Elliot Ward added 1 commit

    added 1 commit

    • 888c8e2a - Issue #3395555: 🦺 add @see comments to Olivero config schema constraints to...

    Compare with previous version

  • 125 125 color_hex:
    126 126 type: string
    127 127 label: 'Color'
    128 constraints:
    129 Regex:
    130 pattern: '/^#[a-fA-F0-9]{6}$/'
    131 message: ":%value is not a valid hexadecimal color."
  • 125 125 color_hex:
    126 126 type: string
    127 127 label: 'Color'
    128 constraints:
    129 Regex:
    130 pattern: '/^#[a-fA-F0-9]{6}$/'
    • :bug: This should also accept 3-character HEX codes I think? #ffeedd is equivalent to #fed, right?

    • Whilst 3 character HEX codes are a thing, Olivero does not currently accept them

      function olivero_theme_settings_validate($form, FormStateInterface $form_state) { if (!preg_match('/^#[a-fA-F0-9]{6}$/', $form_state->getValue('base_primary_color'))) { $form_state->setErrorByName('base_primary_color', t('Colors must be 7-character string specifying a color hexadecimal format.')); } }

      See also similar regex in olivero_form_system_theme_settings_alter()

      However, the only other place that color_hex schema type is used is the Image module. This uses a different hex valdation, Drupal\Component\Utility\Color::validateHex().

      I think we first need to change Olivero to use Color::validateHex() and support 3 character hex codes, then wrap Color::validateHex() as a new constraint/validator and use that in this issue.

    • :bug: Oh but this also was not yet updated to accept 3-character HEX codes; it still only accepts 6-character ones :sweat_smile:

    • AKHIL BABU changed this line in version 8 of the diff

      changed this line in version 8 of the diff

    • Please register or sign in to reply
  • Elliot Ward added 1 commit

    added 1 commit

    • 9affd898 - Issue #3395555: :fire: remove stray : character from color_hex constraint message.

    Compare with previous version

  • Joris Vercammen added 436 commits

    added 436 commits

    • 9affd898...62498926 - 435 commits from branch project:11.x
    • c53a475e - Merge remote-tracking branch 'origin/11.x' into 3395555-add-validation-constraints

    Compare with previous version

  • Joris Vercammen added 1 commit

    added 1 commit

    • 7cf26ca4 - Configure olivero as fully validatable

    Compare with previous version

  • Joris Vercammen added 1 commit

    added 1 commit

    • bd3df4b4 - Remove fully validatable from olivero

    Compare with previous version

  • Adam G-H added 1 commit

    added 1 commit

    • b88b9ecf - Convert Olivero settings to config_target

    Compare with previous version

  • AKHIL BABU added 1 commit

    added 1 commit

    • d8bd35a5 - Issues/3395555: Update Regex to match both 3 and 6 digit hex codes.

    Compare with previous version

  • AKHIL BABU added 1 commit

    added 1 commit

    • d6392833 - Issues/3395555: Update Regex to match both 3 and 6 digit hex codes.

    Compare with previous version

  • AKHIL BABU added 1 commit

    added 1 commit

    • e27350ab - Issues/3395555: Add test to validate hex code.

    Compare with previous version

  • AKHIL BABU added 1 commit

    added 1 commit

    • c47fee99 - Issues/3395555: Coding standard.

    Compare with previous version

  • 279 ];
    280 $valid_hex_codes = [
    281 '0F0',
    282 '#F0F',
    283 '#2ecc71',
    284 '0074cc',
    285 ];
    286
    287 // Visit Olivero's theme settings page.
    288 $this->drupalGet('admin/appearance/settings/olivero');
    289
    290 // Test invalid hex color codes.
    291 foreach ($invalid_hex_codes as $invalid_hex) {
    292 $this->submitForm(['base_primary_color' => $invalid_hex], 'Save configuration');
    293 // Invalid hex codes should throw error.
    294 $this->assertSession()->pageTextContains('"' . $invalid_hex . '" is not a valid hexadecimal color.');
  • AKHIL BABU added 1 commit

    added 1 commit

    • a602660a - Issues/3395555: Use statusMessageContains method in tests.

    Compare with previous version

  • catch @catch started a thread on the diff
  • 126 126 color_hex:
    127 127 type: string
    128 128 label: 'Color'
    129 constraints:
    130 Regex:
    131 # Regex copied from Color::validateHex()
    132 pattern: '/^[#]?([0-9a-fA-F]{3}){1,2}$/'
    • Maintainer

      Why are we copying the pattern instead of using Color::validateHex() as a callback?

    • Very good question!

      Multiple answers:

      1. Strong reason: Color::validateHex() would not allow NULL, but this constraint does. (Anything in config can be marked optional, so NULL must never trigger a validation error) Color::validateHex() does not allow this.
      2. Dreamy reason: The Regex constraint is something that an external tool (no matter whether that's something generating/validating Drupal config or a JSON:API/REST/GraphQL/… client) to also correctly validate this. (This is one of the original dreams if you look back at the original config schema issues.)
    • Captured in 8da34aaa.

      :white_check_mark:

      Edited by Wim Leers
    • Please register or sign in to reply
  • Wim Leers added 1 commit

    added 1 commit

    • 8da34aaa - @catch review: document why does this not call `Color::validateHex()`.

    Compare with previous version

  • Please register or sign in to reply
    Loading