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...
Issue fork display_builder-3540610
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
pdureau commentedComment #3
pdureau commentedComment #4
pdureau commentedComment #6
pdureau commentedWork in progress.
PatternPreset::hasContextsRequirement()is not done yet.Comment #8
pdureau commentedHi 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
Comment #10
mogtofu33 commentedFirst 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,
Comment #11
pdureau commentedThanks a lot. I will have a look
Comment #12
pdureau commentedI am not able to reproduce this problem.
From /admin/structure/page-layout/test/builder
From /admin/structure/types/manage/article/display/default/display-builder
From /admin/structure/display-builder/instance/devel__68cafe0e946b3
I will try.
Indeed, I am reproducing this issue.
Comment #13
pdureau commentedI am not able to save the calculated contexts to config (in order to avoid recalculating them all the time) because of:
What do we do? We merge like that, we ask UIP2 team to fix something and we continue in later beta?
Comment #14
mogtofu33 commentedProbably 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.
Comment #15
pdureau commentedI will test with the same theme and component.
Comment #16
pdureau commentedI am not reproducing this.
This pattern preset has no contexts detected:
Comment #17
pdureau commentedThe entity context is added by token source. Let's create a UIP2 issue about that.
I will check if I have this in 1.0.x branch.
Comment #18
pdureau commentedWith your additional commit, I don't have this anymore:
Follow-up in UIP2: #3549567: TokenSource::getContextDefinitions() always return entity
Comment #19
mogtofu33 commentedComment #20
mogtofu33 commentedThere 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.
Comment #23
mogtofu33 commentedPlaywright error is problematic, need to investigate on a new fork.
Comment #27
mogtofu33 commented