Fix missing validation errors for meta fields in entry edit pages and slideouts #13138
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
In Craft 3, it was possible to add a validation error for the
typeId
attribute (for example, via a custom validation rule in anEntry::EVENT_DEFINE_RULES
event handler), and this error would be displayed below the entry type select field in edit pages:In Craft 4.4.8, this error message will no longer appear and the Entry Type field will not be marked as having errors (the only thing that shows is the "Couldn't save entry" error toast).
This PR fixes this issue, by adding an
'errors'
key to the to the entry type select input's config field array, with a value set to$this->getErrors('typeId')
.Additionally, an
'attribute' => 'typeId'
key is added to the entry type select's config array. This is required for slideouts to render the error, since slideouts use thedata-attribute
for showing errors, which defaults to the field's ID attribute (the Entry Type field has an ID"entryType"
, not"typeId"
).For consistency, this PR also adds the same
'errors'
key to the Parent and Author fields, even if - unlike the Entry Type field - those fields didn't actually support visible validation errors on Craft 3. (For these fields, the IDs and attributes are the same and as such there is no need for anattribute
key.)To give a bit of context and a valid use case for this PR: In the past I've often implemented restrictions related to entry types by implementing custom validation rules for the
typeId
attribute. As an example, the below code makes it impossible to create an entry using the entry type "Child" at the root level of a structure:I was made aware of there not being a visible error message anymore after upgrading a project w/ similar code to Craft 4, so hopefully this PR or a different fix can be merged in. Personally, I feel like being able to surface validation errors like this is a pretty elegant way to implement custom restrictions related to entry types, and I think being able to do the same thing for the Author and Parent fields would be nice.
Related issues