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

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

larowlan created an issue. See original summary.

larowlan’s picture

heddn made their first commit to this issue’s fork.

penyaskito’s picture

Status: Active » Needs work
heddn’s picture

Status: Needs work » Needs review

Implemented suggestions

heddn’s picture

Related javascript tests seem to be failing but I can't reproduce the issues manually. Any suggestions?

smustgrave’s picture

Status: Needs review » Needs work

For 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

heddn’s picture

Status: Needs work » Needs review
heddn’s picture

The lone failure was a build test failure and seems unrelated.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

Left some comments on the MR, thanks!

heddn’s picture

Status: Needs work » Needs review

Responded to feedback.

smustgrave’s picture

1 small comment but can mark after!

penyaskito’s picture

Status: Needs review » Needs work
heddn’s picture

Status: Needs work » Needs review

Posted on the PR but I'm not sure about the extra hardening. Other feedback addressed.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Went 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

larowlan’s picture

Status: Reviewed & tested by the community » Needs review
Related issues: +#3391461: Harden the use of unserialize in InlineBlock via allowed classes

Left some questions on the MR

smustgrave’s picture

Status: Needs review » Needs work

For the feedback from @larowlan

mherchel’s picture

(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

Block plugin settings must opt into strict validation. Use the FullyValidatable constraint. See https://www.drupal.org/node/3404425

Enabling this would 1) solve my specific use case, and 2) open up a world of possibilities with other use cases.

bbrala’s picture

I'll work on this this week

bbrala’s picture

Added 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.

larowlan’s picture

I think your proposed pseudo approach is worth a shot - nice one

bbrala’s picture

I 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.

bbrala’s picture

bbrala’s picture

Ok, 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.

bbrala’s picture

Failures when other fields are invalid. Seems like something related to the context. Will investigate and extend test coverage.

bbrala’s picture

Status: Needs work » Needs review
Issue tags: +Needs change record

Simplified 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.

godotislate’s picture

Status: Needs review » Needs work

Couple more comments on the MR.

bbrala’s picture

Status: Needs work » Needs review

Thanks for the review. Adjusted to most of the feedback.

bbrala’s picture

Issue tags: -Needs change record

Change records made for the new constraints.

godotislate’s picture

Status: Needs review » Needs work

Some layout builder tests are failing now that probably need to be investigated to see if they're related to the changes here.

bbrala’s picture

Yeah just came back to see that and set to nw :P

bbrala’s picture

Think 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.

bbrala’s picture

Status: Needs work » Needs review

green

godotislate’s picture

Status: Needs review » Reviewed & tested by the community

lgtm

nicxvan’s picture

Status: Reviewed & tested by the community » Needs work

Needs some work on nested validations.

bbrala’s picture

Well 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.

I would also want to check whether this has anything to do composite constraints. I wonder what happens if you just double the constraints on a root config schema

^^ Just test that and it recurses twice… so the whole fix for double messages is wrong

The reason you ran into this is that you’re the first to write explicit tests for what happens when you put more that one constraint on a mapping

Another example from Alex

    cat:
      type: mapping
      constraints:
        NotBlank: ~
      mapping:
        type:
          type: string
          constraints:
            Callback:
              callback: [\Drupal\config_test\ConfigValidation, validateCats]
        count:
          type: integer
          constraints:
            Callback:
              callback: [\Drupal\config_test\ConfigValidation, validateCatCount]

So there is a constraint on cat and cat.type

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 ComplexDataConstraintValidator and see if we can break (when just running those on 11.x)

bbrala’s picture

My 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?

bbrala’s picture

Status: Needs work » Needs review
bbrala’s picture

Issue tags: +validation
godotislate’s picture

Status: Needs review » Needs work

The added counter test looks good, and I think this is pretty close. Have a few comments/questions, mostly about docs.

bbrala’s picture

Status: Needs work » Needs review

Fixed feedback, kept one thread open so it is easy to find to know if the change is satisfactory ;)

bbrala’s picture

Issue summary: View changes
bbrala’s picture

Issue summary: View changes
godotislate’s picture

Status: Needs review » Reviewed & tested by the community

lgtm

longwave made their first commit to this issue’s fork.

longwave’s picture

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

Changes 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!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • longwave committed 774f29f6 on 11.3.x
    task: #3535734 Make block.settings.inline_block:* fully validatable
    
    By...

  • longwave committed 1de50d63 on 11.x
    task: #3535734 Make block.settings.inline_block:* fully validatable
    
    By...

Status: Fixed » Closed (fixed)

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