Problem/Motivation

Searching for weight: in all of Drupal core finds 21 matches.

All 21 look like this:

    weight:
      type: integer
      label: 'Weight'

👆 That means an arbitrary integer is allowed. We should add validation.

(See #2920678: Add config validation for the allowed characters of machine names for a similar issue. Note: this blocks #3379725: Make Block config entities fully validatable and many other issues.)

Steps to reproduce

N/A

Proposed resolution

I think that at a minimum, this should be restricted to the largest supported 32-bit integers. Per https://www.php.net/manual/en/reserved.constants.php, that's -2147483648 (PHP_INT_MIN on 32-bit systems) and 2147483647 (PHP_INT_MAX on 32-bit systems).

Note this also matches the supported (signed) integer value ranges in MySQL and MariaDB. Which makes sense, because those use 32 bits of storage.

IOW: "32-bits ought to be enough for expressing weights in Drupal".

Remaining tasks

None.

User interface changes

None.

API changes

API addition: weight config schema data type

Data model changes

None.

Release notes snippet

None.

Issue fork drupal-3426309

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Wim Leers created an issue. See original summary.

wim leers’s picture

Priority: Normal » Major
Status: Active » Needs review
Related issues: +#3421946: [PP-2] Make FilterFormat config entities fully validatable, +#2920441: Add config validation for workflow entities

MR created.

CR created: https://www.drupal.org/node/3426319.

This hard-blocks #3379725: Make Block config entities fully validatable but soft-blocks many more issues, for example #3421946: [PP-2] Make FilterFormat config entities fully validatable, #2920441: Add config validation for workflow entities and many other yet-to-be-created issues.

Weights are pervasive, so standardizing them on a single way to validate them would instantly help much more config reach a higher degree of validatability. Hence bumping to Major priority.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Rerunning the failing javascript test. All green now

The weight type makes a lot of sense, actually been eyeing this ticket for my contrib modules to get validatable.

Appears all instances have label: Weight that was of type integer has been replaced

Change has test coverage too, can be seen https://git.drupalcode.org/issue/drupal-3426309/-/jobs/1015331

wim leers’s picture

Assigned: wim leers » Unassigned

  • catch committed 9c1e1035 on 11.x
    Issue #3426309 by Wim Leers, smustgrave: Add config validation for...
catch’s picture

Version: 11.x-dev » 10.3.x-dev
Status: Reviewed & tested by the community » Fixed

The PHP_MAX_INT was slightly alarming, but what else could we set it to. Looks good. Committed/pushed to 11.x and cherry-picked to 10.3.x, thanks!

  • catch committed 3bc425c2 on 10.3.x
    Issue #3426309 by Wim Leers, smustgrave: Add config validation for...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.