Problem/Motivation
In order to create an upgrade path from layout builder to experience builder, block types provided by the layout builder module need their configuration to be fully validatable
Steps to reproduce
Proposed resolution
Add validation to schema type inline_block and mark it as fully validatable.
Added a Serialized constraint to check if a string is a serialized value.
While we worked on this the conclusion was we need to check for the existence of certain sets of values. Specifically (block_id and block_revision_id) or (block_serialized). This required a new constraint, which ended up being MappingCollectionConstraint, a light extension of Symfony's Collection constaint.
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
Issue fork drupal-3535734
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 #2
larowlanComment #5
penyaskitoComment #6
heddnImplemented suggestions
Comment #7
heddnRelated javascript tests seem to be failing but I can't reproduce the issues manually. Any suggestions?
Comment #8
smustgrave commentedFor the test failures.
One way I like to debug JavaScript tests locally is placing createScreenshots throughout the test to make sure the page is showing what I expected
Comment #9
heddnhttps://www.drupal.org/docs/develop/automated-testing/phpunit-in-drupal/... and more specifically https://github.com/ddev/ddev-selenium-standalone-chrome?tab=readme-ov-fi... helped a lot with getting insight into the failures.
Back to NR
Comment #10
heddnThe lone failure was a build test failure and seems unrelated.
Comment #11
smustgrave commentedLeft some comments on the MR, thanks!
Comment #12
heddnResponded to feedback.
Comment #13
smustgrave commented1 small comment but can mark after!
Comment #14
penyaskitoComment #15
heddnPosted on the PR but I'm not sure about the extra hardening. Other feedback addressed.
Comment #16
smustgrave commentedWent ahead and added the suggestion as it's what was done for DatabaseStorage. Rest of the feedback appears to be addressed
Current failure is broken HEAD for StatusTest
Comment #17
larowlanLeft some questions on the MR
Comment #18
smustgrave commentedFor the feedback from @larowlan
Comment #19
mherchel(was pointed to this issue by @penyaskito at https://drupal.slack.com/archives/C072JMEPUS1/p1759664391938989?thread_t...)
I have a use case for this:
I want to create an custom block type to display remote video and expose it to Canvas. Obviously core Media supports remote video out of the box, so this should be easy. However, I cannot get this inline block into Canvas because
Enabling this would 1) solve my specific use case, and 2) open up a world of possibilities with other use cases.
Comment #20
bbralaI'll work on this this week
Comment #21
bbralaAdded some thoughts on how this could work. I feal this would be possible, but before i dive into solutions, rather have some validation on my thoughts.
Comment #22
larowlanI think your proposed pseudo approach is worth a shot - nice one
Comment #23
bbralaI think I've found a way to use the Collection constraint from symfony to do this, but since im using new Composite constraints this is kinda blocked on #3521131: Add support for Sequentially constraint since that simplifies how we use composites a lot.
Comment #24
bbrala#3521131: Add support for Sequentially constraint has been merged. ^^
Comment #25
bbralaOk, think i got a working implementation, might need some cleaning up. But locally tests make sense and error where they should.
Few things.
Update layout_builder.schema.yml to new constraints. We need NotBlank and NotNull since it could be "null". If we want to only check for existence of the key that wouldnt be required, but i assume NULL is comparable to not there, and the RequiredConstraint doesnt do that but only checks for existence of the key in the value.
Unfortunately we need a MappingCollectionConstraintValidator because of how we pass around typed data.
Comment #26
bbralaFailures when other fields are invalid. Seems like something related to the context. Will investigate and extend test coverage.
Comment #27
bbralaSimplified a lot, no more overwriting.
Did also fix an issue where Composite constraints trigged validation on all child properties, which is not correct.
Think this works like this, powerfull new tool!
Will wait for OK to make a changerecord.
Comment #28
godotislateCouple more comments on the MR.
Comment #29
bbralaThanks for the review. Adjusted to most of the feedback.
Comment #30
bbralaChange records made for the new constraints.
Comment #31
godotislateSome layout builder tests are failing now that probably need to be investigated to see if they're related to the changes here.
Comment #32
bbralaYeah just came back to see that and set to nw :P
Comment #33
bbralaThink the translation issue is unrelated. it also runs green locally.
The other error i had earlier, which was a missing
constaint:key on the Constraint, which is deprecated sometime soon. Bad copy and paste there.Comment #34
bbralagreen
Comment #35
godotislatelgtm
Comment #37
nicxvan commentedNeeds some work on nested validations.
Comment #38
bbralaWell that makes tests green, which also tests a subset of the issue we ran into.
We need to do a few more cases though. Noting here what alex proposed so we don't need to look at slack.
Another example from Alex
Mostly the issue is, we don't want to recurse into the Mapping (or complexdata really) if we are just validating a constraint. The change in the test branch validates it works for the cases I tested, but we want to make sure other cases go well also.
We can probable test that in
ComplexDataConstraintValidatorand see if we can break (when just running those on 11.x)Comment #39
bbralaMy comment got eaten. :(
Added a new test. Without the changes to RecursiveContextualValidator it fails on call count to constraints.
If i remove the is_root_call condition from RecursiveContextualValidator then ./core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php will fail because it is not getting all violations.
Not sure what is next to really check. Seems this (combined with green pipeline) is good enough?
Comment #41
bbralaComment #42
bbralaComment #43
godotislateThe added counter test looks good, and I think this is pretty close. Have a few comments/questions, mostly about docs.
Comment #44
bbralaFixed feedback, kept one thread open so it is easy to find to know if the change is satisfactory ;)
Comment #45
bbralaComment #46
bbralaComment #47
godotislatelgtm
Comment #49
longwaveChanges all make sense and as @larowlan pointed out in Slack this will help open a Layout Builder to Canvas upgrade path.
Committed and pushed 1de50d63dcb to 11.x and 774f29f6033 to 11.3.x. Thanks!