Problem/Motivation

Steps to reproduce

Setup :

  • Display Builder beta 2
  • UI Patterns 2 dev release
  • UI Suite DaisyUI dev release

Build the default display with Layout Builder :

  • Remove everything
  • Use Card as section
  • Map
    • Image field with slot image
    • Title field with slot title
    • Body field with slot text
    • Tags field with slot actions (use component per item —> badge —> map label with Field Formatter > Label)
  • Save

GOTO Manage Display :

  • Activate Display Builder with Default profile
  • Goto Display Builder and Publish the initialization from Layout Builder
  • Save the whole Card as preset
  • The preset doesn’t appear

In logs we have following Warning and errors :

WARNING #01

Warning: Undefined array key "source_id" in Drupal\display_builder\Entity\PatternPreset->getContextsFromComponent() (line 257 of /var/www/html/web/modules/contrib/display_builder/src/Entity/PatternPreset.php)
#0 /var/www/html/web/core/includes/bootstrap.inc(104): _drupal_error_handler_real()
#1 /var/www/html/web/modules/contrib/display_builder/src/Entity/PatternPreset.php(257): _drupal_error_handler()
#2 /var/www/html/web/modules/contrib/display_builder/src/Entity/PatternPreset.php(226): Drupal\display_builder\Entity\PatternPreset->getContextsFromComponent()
#3 /var/www/html/web/modules/contrib/display_builder/src/Entity/PatternPreset.php(158): Drupal\display_builder\Entity\PatternPreset->getContextFromSource()
#4 /var/www/html/web/modules/contrib/display_builder/src/Entity/PatternPreset.php(187): Drupal\display_builder\Entity\PatternPreset->getContexts()
#5 /var/www/html/web/modules/contrib/display_builder/src/Plugin/display_builder/Island/PresetLibraryPanel.php(64): Drupal\display_builder\Entity\PatternPreset->areContextsSatisfied()
#6 /var/www/html/web/modules/contrib/display_builder/src/IslandPluginBase.php(315): Drupal\display_builder\Plugin\display_builder\Island\PresetLibraryPanel->build()
#7 /var/www/html/web/modules/contrib/display_builder/src/Plugin/display_builder/Island/PresetLibraryPanel.php(104): Drupal\display_builder\IslandPluginBase->reloadWithGlobalData()
#8 /var/www/html/web/modules/contrib/display_builder/src/Event/DisplayBuilderEventsSubscriber.php(169): Drupal\display_builder\Plugin\display_builder\Island\PresetLibraryPanel->onPresetSave()
#9 /var/www/html/web/modules/contrib/display_builder/src/Event/DisplayBuilderEventsSubscriber.php(128): Drupal\display_builder\Event\DisplayBuilderEventsSubscriber->dispatchToIslands()
#10 /var/www/html/vendor/symfony/event-dispatcher/EventDispatcher.php(246): Drupal\display_builder\Event\DisplayBuilderEventsSubscriber->onPresetSave()
#11 /var/www/html/vendor/symfony/event-dispatcher/EventDispatcher.php(206): Symfony\Component\EventDispatcher\EventDispatcher::{closure:Symfony\Component\EventDispatcher\EventDispatcher::optimizeListeners():241}()
#12 /var/www/html/vendor/symfony/event-dispatcher/EventDispatcher.php(56): Symfony\Component\EventDispatcher\EventDispatcher->callListeners()
#13 /var/www/html/web/modules/contrib/display_builder/src/Controller/ApiControllerBase.php(96): Symfony\Component\EventDispatcher\EventDispatcher->dispatch()
#14 /var/www/html/web/modules/contrib/display_builder/src/Controller/ApiController.php(612): Drupal\display_builder\Controller\ApiControllerBase->createEventWithEnabledIsland()
#15 /var/www/html/web/modules/contrib/display_builder/src/Controller/ApiController.php(383): Drupal\display_builder\Controller\ApiController->dispatchDisplayBuilderEvent()
#16 [internal function]: Drupal\display_builder\Controller\ApiController->saveAsPreset()

WARNING #02

Warning: Undefined array key "source" in Drupal\display_builder\Entity\PatternPreset->getContextsFromComponent() (line 257 of /var/www/html/web/modules/contrib/display_builder/src/Entity/PatternPreset.php)
#0 /var/www/html/web/core/includes/bootstrap.inc(104): _drupal_error_handler_real()
#1 /var/www/html/web/modules/contrib/display_builder/src/Entity/PatternPreset.php(257): _drupal_error_handler()
#2 /var/www/html/web/modules/contrib/display_builder/src/Entity/PatternPreset.php(226): Drupal\display_builder\Entity\PatternPreset->getContextsFromComponent()
#3 /var/www/html/web/modules/contrib/display_builder/src/Entity/PatternPreset.php(158): Drupal\display_builder\Entity\PatternPreset->getContextFromSource()
#4 /var/www/html/web/modules/contrib/display_builder/src/Entity/PatternPreset.php(187): Drupal\display_builder\Entity\PatternPreset->getContexts()
#5 /var/www/html/web/modules/contrib/display_builder/src/Plugin/display_builder/Island/PresetLibraryPanel.php(64): Drupal\display_builder\Entity\PatternPreset->areContextsSatisfied()
#6 /var/www/html/web/modules/contrib/display_builder/src/IslandPluginBase.php(315): Drupal\display_builder\Plugin\display_builder\Island\PresetLibraryPanel->build()
#7 /var/www/html/web/modules/contrib/display_builder/src/Plugin/display_builder/Island/PresetLibraryPanel.php(104): Drupal\display_builder\IslandPluginBase->reloadWithGlobalData()
#8 /var/www/html/web/modules/contrib/display_builder/src/Event/DisplayBuilderEventsSubscriber.php(169): Drupal\display_builder\Plugin\display_builder\Island\PresetLibraryPanel->onPresetSave()
#9 /var/www/html/web/modules/contrib/display_builder/src/Event/DisplayBuilderEventsSubscriber.php(128): Drupal\display_builder\Event\DisplayBuilderEventsSubscriber->dispatchToIslands()
#10 /var/www/html/vendor/symfony/event-dispatcher/EventDispatcher.php(246): Drupal\display_builder\Event\DisplayBuilderEventsSubscriber->onPresetSave()
#11 /var/www/html/vendor/symfony/event-dispatcher/EventDispatcher.php(206): Symfony\Component\EventDispatcher\EventDispatcher::{closure:Symfony\Component\EventDispatcher\EventDispatcher::optimizeListeners():241}()
#12 /var/www/html/vendor/symfony/event-dispatcher/EventDispatcher.php(56): Symfony\Component\EventDispatcher\EventDispatcher->callListeners()
#13 /var/www/html/web/modules/contrib/display_builder/src/Controller/ApiControllerBase.php(96): Symfony\Component\EventDispatcher\EventDispatcher->dispatch()
#14 /var/www/html/web/modules/contrib/display_builder/src/Controller/ApiController.php(612): Drupal\display_builder\Controller\ApiControllerBase->createEventWithEnabledIsland()
#15 /var/www/html/web/modules/contrib/display_builder/src/Controller/ApiController.php(383): Drupal\display_builder\Controller\ApiController->dispatchDisplayBuilderEvent()
#16 [internal function]: Drupal\display_builder\Controller\ApiController->saveAsPreset()
#17 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()

ERROR

TypeError: Drupal\display_builder\Entity\PatternPreset::getContextFromSource(): Argument #1 ($source_id) must be of type string, null given, called in /var/www/html/web/modules/contrib/display_builder/src/Entity/PatternPreset.php on line 257 in Drupal\display_builder\Entity\PatternPreset->getContextFromSource() (line 221 of /var/www/html/web/modules/contrib/display_builder/src/Entity/PatternPreset.php).

Other building scenario : If we build directly from Display Builder (without pre-building and importing from Layout Builder) the preset is getting saved and is usable.

But be aware we get following errors in log messages (don’t know if that is relevant …) :

Type : ui_patterns

Location : https://ui-suite-demo.ddev.site/api/display-builder/preset/698dab65d2d70...
Referrer : https://ui-suite-demo.ddev.site/admin/structure/types/manage/article/dis...
Message : Entity not found in context
Severity : Error

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

g4mbini created an issue. See original summary.

pdureau’s picture

Assigned: Unassigned » pdureau
Issue tags: +display_builder-1.0.0-beta3

I will have a look soon and try to fix it for beta3

pdureau’s picture

Title: Presets from elements built with Layout Builder doesn’t save, raise error and prevent additional other presets » Error when saving a presets after a migrtation from Layout Builder
Assigned: pdureau » Unassigned
Status: Active » Postponed (maintainer needs more info)

Hi Michaal,

Thanks for the detailed instructions. I am not reproducing. The only difference between my test and your description is the Display Builder version: I am on 1.0.0-dev, you are on 1.0.0-beta2.

I can test again but can you share your entity view display config entity first?

pdureau’s picture

Tested with 1.0.0-beta2. Still not reproducing.

grimreaper’s picture

Hello,

I do not reproduce too. Tested with latest dev version of 1.0.x and latest version of UIP 2.

Tested on ui_suite_bootstrap.

pdureau’s picture

Not easy to reproduce, so moved out of beta3 scope.

steveoriol’s picture

I added the following lines as a workaround for now. It seems to be working for the moment...

web/modules/contrib/display_builder/src/Entity/PatternPreset.php (line 257) :

    foreach ($props as $prop_source) {
      if (!is_array($prop_source)) {
        continue;
      }
      if (empty($prop_source['source']) || empty($prop_source['source_id'])) {
        continue;
      }
      $contexts = \array_merge($contexts, $this->getContextFromSource($prop_source['source_id'], $prop_source['source']));
    }
pdureau’s picture

Status: Postponed (maintainer needs more info) » Active
Issue tags: -display_builder-1.0.0-beta +display_builder-1.0.0-beta3

Hii Steve,

So you are reproducing the issue? That's great, thanks a lot. Can you propose a MR?

With a phpunit, it would be even better :)

Moving back to beta3 because we are waiting the next release of UI Patterns, so we may have time to merge this one before.

steveoriol’s picture

There you go, I did an MR. But I don't know if it's normal for the props table to be empty or not...

pdureau’s picture

Status: Active » Needs review

I am reproducing by the way and it seems related to #3574921: Instance::moveToSlot() error when an ancestor is a not a SDC which is about some source data being lost, especially the source_id

So, the root cause will be fixed there, but anyway it i good to have a more defensive behaviour thanks to your MR. I will review.

pdureau’s picture

Issue summary: View changes
pdureau’s picture

Title: Error when saving a presets after a migrtation from Layout Builder » Error when saving a presets after a migration from Layout Builder
g4mbini’s picture

It saves the preset now that I can re-use, but in the saved presets we lose all styles that were added.

pdureau’s picture

pdureau’s picture

Status: Needs review » Postponed
mogtofu33’s picture

pdureau’s picture

Status: Postponed » Needs review

It saves the preset now that I can re-use, but in the saved presets we lose all styles that were added.

Michael, is it better now #3574921: Instance::moveToSlot() error when an ancestor is a not a SDC has been merged?

g4mbini’s picture

Status: Needs review » Needs work
StatusFileSize
new536.96 KB

Still ... Presets is saved but when I use it, Styles used are not saved in the preset.

I attached a screenshot.

mogtofu33’s picture

Version: 1.0.0-beta2 » 1.0.x-dev
Issue tags: -display_builder-1.0.0-beta4 +display_builder-1.0.0-beta5