Problem/Motivation

This logic:

    // Validate that each prop source resolves into a value that is considered
    // valid by the destination SDC prop.
    // @todo Move to validation constraint.
    foreach ($component_instance_uuids as $component_instance_uuid) {
      $component_id = $tree->getComponentId($component_instance_uuid);
      $props_values = $this->resolveComponentProps($component_instance_uuid);
      try {
        $component = $this->getComponentPluginManager()->find($component_id);
        $this->getComponentValidator()->validateProps($props_values, $component);
      }
      catch (ComponentNotFoundException $e) {
        throw new \LogicException(sprintf('The component instance with UUID %s uses component %s but does not exist! Put a breakpoint here and figure out why.', $component_instance_uuid, $component_id));
      }
      catch (InvalidComponentException $e) {
        throw new \LogicException(sprintf('The component instance with UUID %s uses component %s and receives some invalid props! Put a breakpoint here and figure out why.', $component_instance_uuid, $component_id));
      }
    }

… belongs in a validation constraint.

It'll:

  1. simplify the field type logic
  2. allow that same logic to be reused in multiple things of #3444424: [META] Configuration management: define needed config entity types, starting with the "component" config entity that #3444417: "Developer-created components": mark which SDCs should be exposed in XB introduced

Steps to reproduce

Proposed resolution

Do the above.

If #3452397: Allow specifying default props values when opting an SDC in for XB lands before this, its config schema should be updated to use this new validation constraint too.

Remaining tasks

User interface changes

API changes

Data model changes

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.

tedbow’s picture

Assigned: Unassigned » tedbow

Working on this

tedbow’s picture

Assigned: tedbow » Unassigned
Status: Active » Needs review
lauriii’s picture

Assigned: Unassigned » tedbow
Status: Needs review » Needs work

Assigning back to @tedbow to address feedback.

tedbow’s picture

Assigned: tedbow » larowlan
Status: Needs work » Needs review

@larowlan, thanks for the review. Addressed your feedback

tedbow’s picture

Assigned: larowlan » Unassigned

@larowlan on 2nd thought I am going to unassign this because I think your feedback was pretty straight forward. Welcome your review though

wim leers’s picture

Assigned: Unassigned » tedbow
Status: Needs review » Needs work
Issue tags: +Needs tests

This part of the issue summary is not yet complete:

  1. allow that same logic to be reused in multiple things of #3444424: [META] Configuration management: define needed config entity types, starting with the "component" config entity that #3444417: "Developer-created components": mark which SDCs should be exposed in XB introduced

… but I laid the groundwork for you to make it easy:

  1. https://git.drupalcode.org/project/experience_builder/-/merge_requests/6... → this introduced the failure Drupal\Core\Config\Schema\SchemaIncompleteException: Schema errors for field.field.node.article.field_xb_demo with the following errors: 0 [default_value.0] BLA BLA BLA
  2. https://git.drupalcode.org/project/experience_builder/-/merge_requests/6... → that opts in this particular test to strict config schema checking, to actually see the aforementioned fake validation error
  3. https://git.drupalcode.org/project/experience_builder/-/merge_requests/6... → allows reusing the existing validation logic you wrote :)

This now really still needs tests, that verify invalid values are caught, both for component tree field instances on actual nodes, as well as in default field values in config.

wim leers’s picture

#3455728: FieldType: Support storing component *trees* instead of *lists* is in — let's get this done next! First let's get this to green, and then I think merging #3460856 into this will be the least amount of effort, as described over at #3460856-5: Create validation constraint for ComponentTreeStructure.

tedbow’s picture

@Wim Leers I am still working on this(but finished for the day) but feel to take a look to see if totally on the wrong track anywhere.

wim leers’s picture

This was kinda heading in the right direction! 👍

Changes I made:

  • I made the constraint violation test coverage use the same test infrastructure as Drupal core.
  • Logic was added to ValidComponentTreeConstraintValidator::validate() that re-ran the same validation logic — removed.
  • Due to Typed Data magic, it was impossible to get to the values actually passed to the field instance — fixed that 👍

Definitely tricky stuff!


The piece still missing from this MR: explicit test coverage for type: type: field.value.component_tree — i.e. when there is a component tree defined in configuration.

Manually triggering this is easy: delete the default_value.0.props line from config/optional/field.field.node.article.field_xb_demo.yml, and you'll get this test failure:

1) Drupal\Tests\experience_builder\Functional\EndToEndDemoIntegrationTest::test
Drupal\Core\Config\Schema\SchemaIncompleteException: Schema errors for field.field.node.article.field_xb_demo with the following errors: 0 [default_value.0] The array must contain a "props" key.
wim leers’s picture

Now it's green.

What remains is the test coverage mentioned above. And I think it'd be good to tighten the test slightly: no extraneous keys should be allowed either.

tedbow’s picture

Assigned: tedbow » wim leers
Status: Needs work » Needs review

Added more test cases. I think this is ready for review.

I have 1 question/comment on the MR but I think that can be handled in follow-up, if needed

wim leers’s picture

I was going to RTBC this, after self-fixing my review feedback (and making the connection to #3455629: [PP-1] [META] 7. Content Templates — aka "default layouts" — affects the tree+props data model explicit) and implement my proposed solution to the question/comment on the MR you referred to in #13.

But then I realized that the config test coverage I requested at the bottom of #11 is not yet present. That's a crucial piece, and it helps pave the path for #3455629 (as well as "patterns", whose definition is currently still vague, see #3455036: Clarify "components" vs "elements" vs "patterns").

wim leers’s picture

Issue tags: +blocker

This is more complex than I hoped, so let's once #14 is addressed, let's land this, and let's not fold #3460856: Create validation constraint for ComponentTreeStructure into this. Instead, this is now definitely the blocker for #3460856.

tedbow’s picture

RE

The piece still missing from this MR: explicit test coverage for type: type: field.value.component_tree — i.e. when there is a component tree defined in configuration.

Isn't this covered in

\Drupal\Tests\experience_builder\Kernel\Plugin\Field\FieldType\ComponentTreeItemTest::testDefaultFieldValue

where it expects the error Schema errors for field.field.node.article.field_xb_test with the following errors: 0 [default_value.0] The array must contain a "tree" key.. This almost the same error you pointed out just for different field. This is save configuration or did you mean explicitly in config .yml file?

wim leers’s picture

Ah … that's fair! 😅 I didn't realize that because it is in ComponentTreeItemTest. Sorry! 🙈

Can you please move that into a new tests/src/Kernel/Config/DefaultFieldValueTest.php instead? 🙏 I think that'd be clearer, and make it easier to find this test, and expand it in the future.

Once you've done that, definitely remove the Needs tests and re-assign to me for review 😊🙏

tedbow’s picture

Assigned: tedbow » wim leers
Status: Needs work » Needs review
Issue tags: -Needs tests

Did #17, had to make new test trait for this. Also made some change to `ComponentTreeItemTest` because in refactoring to the new test class I realized setUp() and the class constants where needed for testCalculateDependencies() which I think was confusing and made changes that were not needed for the new test method to pass. See MR comments

wim leers’s picture

Your own remark https://git.drupalcode.org/project/experience_builder/-/merge_requests/6... is not yet addressed, and there is a suggested solution for it.

Because that needs to be addressed anyway: please also move the 2 commits you added to comply with an upstream change to #3462143: CI: phpcs job failing due to upstream changes in Drupal core: unused variables in catch statements now disallowed, I just created that after @bnjmnm asked for help to figure out why #3461435: End-to-end test that tests both the client (UI) and server was mysteriously failing. 😅

tedbow’s picture

Assigned: tedbow » wim leers
Status: Needs work » Needs review
wim leers’s picture

Status: Needs review » Reviewed & tested by the community

  • Wim Leers committed cf4bebb7 on 0.x authored by tedbow
    Issue #3456024 by tedbow, Wim Leers: Lift most logic out of...
wim leers’s picture

Status: Reviewed & tested by the community » Fixed
wim leers’s picture

Assigned: wim leers » Unassigned

Status: Fixed » Closed (fixed)

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