Problem/Motivation

Following #3534190: Pattern presets storage and dependencies

Pattern Presets conditions of availability in the "Pattern library" panel have not been properly implemented yet, so we see in this panel presets we are not supposed to have access.

Proposed resolution

We need to make patterns available if the contexts of the sources stored in the pattern are compatible with the contexts of the current display builder.

For example, a pattern with 'field:node:article:title' must not be avaialble if the entity context is missing.

A pattern with view_rows source, must not be available outside of a View context. And so on...

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

pdureau created an issue. See original summary.

pdureau’s picture

Title: Context & dependency management for Pattern presets » Context management for Pattern presets
pdureau’s picture

pdureau’s picture

Assigned: Unassigned » pdureau

pdureau’s picture

Status: Active » Needs work

Work in progress.

PatternPreset::hasContextsRequirement() is not done yet.

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

pdureau’s picture

Assigned: pdureau » mogtofu33
Status: Needs work » Needs review

Hi Jean,

Ready for review. Tested with entity view, page layout & dev tools. Tested with slots sources, props sources, nested components. All looks good.

I have also did another change in the MR: printing the label of the theme instead of the machine name in Patterns entity list builder.

There are some playwright fails but i have different results locally so i am not sure it is related to the current MR: https://git.drupalcode.org/project/display_builder/-/jobs/6555885

There will be a follow-up issue for a very specific complementary task: #3546964: Better context management in presets

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

mogtofu33’s picture

Assigned: mogtofu33 » pdureau
Status: Needs review » Needs work

First quick test and review. I fixed some style, name or logic issues.

Seems to work fine, as a detail I always got 'Entity' as context even if it's a preset without any context (created from devel instance for example). Which seems strange.

Then I see that the PatternPreset::getContexts() is called each time the library of presets is loaded for each preset (even the non compatible ones).
It seems expensive, could the contexts be stored on the entity the first time and when edited only? So it can be cached. I tested with full entity cache to ensure it was not cached anywhere.

An other unrelated issue that I thought was fix is the preset not persisting in the builder (tested without cache this time):
Create a preset, add the preset to the builder: it's rendered, history added, preset added to logs! But then click it and the instanceform will be empty. Refresh and the preset is not here anymore, with no logs...
Can you confirm this problem? I guess it's more an api controller problem,

pdureau’s picture

Can you confirm this problem? I guess it's more an api controller problem,

Thanks a lot. I will have a look

pdureau’s picture

Seems to work fine, as a detail I always got 'Entity' as context even if it's a preset without any context (created from devel instance for example). Which seems strange.

I am not able to reproduce this problem.

From /admin/structure/page-layout/test/builder

  • A card with page title in slot >> ✅ Page context
  • Just a button >> ✅ No context

From /admin/structure/types/manage/article/display/default/display-builder

  • A card with node title in slot >> ✅ Entity context
  • A button with entity link in prop >> ✅ Entity context
  • Just a button >> ✅ No context

From /admin/structure/display-builder/instance/devel__68cafe0e946b3

  • Just a button >> ✅ No context

Then I see that the PatternPreset::getContexts() is called each time the library of presets is loaded for each preset (even the non compatible ones).
It seems expensive, could the contexts be stored on the entity the first time and when edited only? So it can be cached. I tested with full entity cache to ensure it was not cached anywhere.

I will try.

An other unrelated issue that I thought was fix is the preset not persisting in the builder (tested without cache this time):
Create a preset, add the preset to the builder: it's rendered, history added, preset added to logs! But then click it and the instanceform will be empty. Refresh and the preset is not here anymore, with no logs...
Can you confirm this problem? I guess it's more an api controller problem,

Indeed, I am reproducing this issue.

pdureau’s picture

Assigned: pdureau » mogtofu33
Status: Needs work » Needs review

I am not able to save the calculated contexts to config (in order to avoid recalculating them all the time) because of:

Uncaught PHP Exception Drupal\Core\Config\UnsupportedDataTypeConfigException: "Invalid data type for config element display_builder.pattern_preset.68d594d360b6d:contexts.context_requirements" at /home/pierre/Projects/Drupal/ui_patterns_2/web/core/lib/Drupal/Core/Config/StorableConfigBase.php line 202

What do we do? We merge like that, we ask UIP2 team to fix something and we continue in later beta?

mogtofu33’s picture

Assigned: mogtofu33 » pdureau
Status: Needs review » Needs work

Probably serialization problem with Context classes.

That's strange from fresh install I still have the entity context even with no context in the preset. Tested with db_theme_test and component test_simple.

pdureau’s picture

That's strange from fresh install I still have the entity context even with no context in the preset. Tested with db_theme_test and component test_simple.

I will test with the same theme and component.

pdureau’s picture

Assigned: pdureau » mogtofu33
Status: Needs work » Needs review

That's strange from fresh install I still have the entity context even with no context in the preset. Tested with db_theme_test and component test_simple.

I am not reproducing this.

This pattern preset has no contexts detected:

source_id: component
source:
  component:
    component_id: 'display_builder_theme_test:test_simple'
pdureau’s picture

Assigned: mogtofu33 » pdureau
Status: Needs review » Needs work

The entity context is added by token source. Let's create a UIP2 issue about that.

Create a preset, add the preset to the builder: it's rendered, history added, preset added to logs! But then click it and the instanceform will be empty. Refresh and the preset is not here anymore, with no logs...

I will check if I have this in 1.0.x branch.

pdureau’s picture

Assigned: pdureau » mogtofu33
Status: Needs work » Reviewed & tested by the community

With your additional commit, I don't have this anymore:

Create a preset, add the preset to the builder: it's rendered, history added, preset added to logs! But then click it and the instanceform will be empty. Refresh and the preset is not here anymore, with no logs...

Follow-up in UIP2: #3549567: TokenSource::getContextDefinitions() always return entity

mogtofu33’s picture

Status: Reviewed & tested by the community » Needs review
mogtofu33’s picture

Assigned: mogtofu33 » Unassigned
Status: Needs review » Fixed

There is a strange issue with Playwright test, but not sure it's related. So let's go with this, added a minimum test and some renaming.

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

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

Maintainers, please credit people who helped resolve this issue.

  • mogtofu33 committed 4dee4ed9 on 1.0.x authored by pdureau
    [#3540610] feat: Context management for Pattern presets
    
    By: pdureau
    By...
mogtofu33’s picture

Assigned: Unassigned » mogtofu33
Status: Fixed » Needs work

Playwright error is problematic, need to investigate on a new fork.

mogtofu33 changed the visibility of the branch 3540610-context-management-for to hidden.

  • mogtofu33 committed 2669b00c on 1.0.x
    [#3540610] fix: unrelated remove dependency on...
mogtofu33’s picture

Assigned: mogtofu33 » Unassigned
Status: Needs work » Fixed

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

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

Maintainers, please credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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