Problem/Motivation
Settings are not populated to the template variables as they are not added to the render array.
Proposed resolution
UI Patterns module currently does not provide any pre-render hook for layout patterns that allow other modules manipulate the render array. Something similar happens with the layout_builder (#3080684: Provide output alter event for layout builder). So the only way I found to add the pattern settings is by altering the plugin class in the pattern plugin info.
Remaining tasks
Review, consider other approaches.
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
TBD.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | ui_patterns_settings-settings_in_layout_patterns-3093284-2.patch | 1.99 KB | manuel.adan |
Comments
Comment #2
manuel.adanComment #3
christian.wiedemann commentedIs it not possible to use preprocess for your use case. Do you use it with layout builder?
I think it is not a good idea to set a pattern class because the settings should work with other possible pattern implementations.
Comment #4
christian.wiedemann commentedComment #5
idiaz.ronceroWe are facing the same issue, using Drupal 8.8.1
When using ui_patterns_settings with display suite enabled, the settings appear correctly on the pattern template.
Steps to reproduce:
- Enable ds, ui_patterns_ds, ui_patterns_settings.
- Create settings for a pattern and use them (in my case on a paragraph view mode)
- Render the entity. Use kint() inside the template to access the variables. The settings appear and are directly usable (i.e. if I have a setting called textfieldw with a vale of "test", I receive a 'textfield' -> 'test' and can render {{ textfield }} )
But if you uninstall display suite, you face a settings-less render array: the same textfield setting is set to NULL.
If you set a few breakpoints you can check that src/Element/PatternSettings::processSettings() works with layout builder and display suite but it won't work on the default (core) case.
Unlike the DS and Layout Builder cases,
$settings = isset($element['#settings']) ? $element['#settings'] : [];returns an empty array as $element['#settings'] is not populated. So, when you are not using DS or Layout Builder, you are left with an empty$settingsThe patch on #2 corrects this. I think it should be applied, because the module should be usable with Drupal's core.
Comment #6
christian.wiedemann commented@idiaz.roncero So which module do you use to apply a layout to your entity when you disabled ds. core/field_layout ?
Comment #7
idiaz.ronceroCore's Field Layout and Layout Discovery. Sorry, forgot to mention that.
Comment #8
christian.wiedemann commentedI did some tests. The patch works fine with other implementations. Thanks!
Comment #9
christian.wiedemann commentedComment #11
christian.wiedemann commentedComment #12
christian.wiedemann commented