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.

Comments

manuel.adan created an issue. See original summary.

manuel.adan’s picture

Assigned: manuel.adan » Unassigned
Status: Active » Needs review
Issue tags: +Needs tests
StatusFileSize
new1.99 KB
christian.wiedemann’s picture

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

christian.wiedemann’s picture

Status: Needs review » Postponed (maintainer needs more info)
idiaz.roncero’s picture

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

      $settings = isset($element['#settings']) ? $element['#settings'] : []; // ALWAYS EMPTY
      // Handling display suite pattern.
      if (empty($settings)) {
        $settings = isset($element['#ds_configuration']['layout']['settings']['pattern']['settings']) ? $element['#ds_configuration']['layout']['settings']['pattern']['settings'] : [];
      }
      // Handling layout builder.
      if (empty($settings) && isset($element['#layout'])) {
        /** @var \Drupal\ui_patterns_layout_builder\Plugin\Layout\PatternLayoutBuilder $layout */
        $layout = $element['#layout'];
        $configuration = $layout->getConfiguration();
        $settings = isset($configuration['pattern']['settings']) ? $configuration['pattern']['settings'] : [];
      }

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 $settings

The patch on #2 corrects this. I think it should be applied, because the module should be usable with Drupal's core.

christian.wiedemann’s picture

@idiaz.roncero So which module do you use to apply a layout to your entity when you disabled ds. core/field_layout ?

idiaz.roncero’s picture

Core's Field Layout and Layout Discovery. Sorry, forgot to mention that.

christian.wiedemann’s picture

I did some tests. The patch works fine with other implementations. Thanks!

christian.wiedemann’s picture

Status: Postponed (maintainer needs more info) » Fixed

christian.wiedemann’s picture

Status: Fixed » Closed (fixed)
christian.wiedemann’s picture