Problem/Motivation
field ui settings has 1 property path that is not yet validatable:
./vendor/bin/drush config:inspect --filter-keys=field_ui.settings --detail --list-constraints --fields=key,validatability,constraints
➜ 🤖 Analyzing…
---------------------------------------------- ------------- ------------------------------------------
Key Validatable Validation constraints
---------------------------------------------- ------------- ------------------------------------------
field_ui.settings 75% ValidKeys: '<infer>'
field_ui.settings: Validatable ValidKeys: '<infer>'
field_ui.settings:_core Validatable ValidKeys:
- default_config_hash
field_ui.settings:_core.default_config_hash Validatable NotNull: { }
Regex: '/^[a-zA-Z0-9\-_]+$/'
Length: 43
↣ PrimitiveType: { }
field_ui.settings:field_prefix NOT ⚠️ @todo Add validation constraints here
---------------------------------------------- ------------- ------------------------------------------
Steps to reproduce
- Get a local git clone of Drupal core
11.x. composer require drupal/config_inspector— or manually install https://www.drupal.org/project/config_inspector/releases/2.1.5 or newer (which supports Drupal 11!)composer require drush/drushvendor/bin/drush config:inspect --filter-keys=field_ui.settings --detail --list-constraints
Proposed resolution
Add validation constraints to:
field_ui.settings:field_prefix
This requires looking at the existing code and admin UI (if any) to understand which values could be considered valid. Eventually this needs to be reviewed by the relevant subsystem maintainer.
For examples, search *.schema.yml files for the string constraints: 😊
Reach out to @borisson_ or @wimleers in the #distributions-and-recipes.
Remaining tasks
field_ui.settings:field_prefix
User interface changes
None.
API changes
Data model changes
More validation 🚀
Release notes snippet
None.
Issue fork drupal-3417363
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
Comment #4
narendrarComment #5
narendrarComment #6
wim leers🏓 I don't think this is quite right yet.
Comment #7
narendrarComment #8
wim leersComment #9
narendrarComment #10
borisson_This looks good to me, i don't think we should decrease the size even further.
Comment #11
catchWhat would happen if you had an existing field prefix that's invalid according to the new validation?
Comment #12
smustgrave commentedIs this something that can be fixed though after the field is created?
Comment #13
narendrarI think that is already handled in
core/modules/field/src/Entity/FieldStorageConfig::__constructComment #14
wim leers#11++ … and #13++ for answering it 😄
But … @narendraR, you literally quoted the code that proves that the validation constraints you added to the config schema are incorrect 😅
Comment #15
narendrarAdding
_in the end of field prefix failedcore/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest::testFieldPrefix. Either that test needs to be adjusted as per new validation rule or _ in the end of field prefix is not necessary. For now, I am removing the _ from field prefix end.Comment #16
narendrarComment #17
wim leers#15: that's not the difference between the two: the field name (and hence also the prefix) must start with
[0-9].Comment #18
narendrarSorry, but I don't get #17. As per #13,
Only lowercase alphanumeric characters and underscores are allowed, and only lowercase letters and underscore are allowed as the first character.Comment #19
wim leersAh, I see — I had only seen the two underscore-related commits (eafb29c0 and 5b82dd9a), not the one that fixed the regex (f7ea3188) — sorry about that! 🙈
Indeed, I don't think a trailing
_is required for the prefix — it could also be justfooas a prefix for example.I think this looks ready now, except for one nit (left a suggestion for it) and one question/bit of ambiguity.
Comment #20
narendrarComment #21
wim leersLooks good now!
Comment #22
catchWith #11 I actually meant what happens if the field prefix is over 30 characters already (although glad my vague question found a real bug).
Comment #23
catchBack to needs review for #22.
Comment #24
phenaproximaI'm guessing we need an update path to handle that case. :(
Comment #25
narendrarComment #26
narendrarComment #27
catchSorry I'm not sure about the update path either - this is silently updating someone's config and field names aren't changeable once they make a new field, which they might do without realising.
I don't really believe anyone has a 40 (or even 31) character field prefix, but if their field prefix was
iloveantidisestablishmentarianismverymuchwould we really want to shorten that toiloveantidisestablishmentarianismverymu.If all that happens when the field prefix is too long, is they get a validation error if they try to save that form again, could we add a hook_requirements() warning, then they can fix it to a shorter string of their choosing? Or something like that seems OK as long as config import/export is unaffected.
Comment #28
wim leers#27: a 40-character long prefix is impossible already thanks to
\Drupal\field\Entity\FieldStorageConfig::preSaveNew()doing:I agree that should be better documented though.
Comment #29
narendrarNot sure what next should be done in this issue, hence marking it for another review.
Comment #30
wim leersAddressed @catch's review like I suggested in #28: with slightly expanded docs. I think this is ready now.
Comment #31
alexpottDiscussed with @catch - I don't think we should have an update path here. Because as wim points out on the less you’d already have problems if it was over 31 characters… and practically you do with the new limit of 30… every field name would have to only be 2 letters… so I just so think the upgrade path is worth it.
Also see #27
Comment #32
phenaproximaOkay, I'm going to guess this is therefore RTBC once tests pass!
Comment #33
alexpottCommitted and pushed e63b0c228a to 11.x and fb746dae75 to 10.3.x. Thanks!