Fix incomplete default CE generation

Created on 18 March 2024, 9 months ago
Updated 19 April 2024, 8 months ago

Problem/Motivation

Default CE generation it not 100% yet. We need to set some default components to get the proper config object eg.: "is_slot" should have a default value every time since some existing code depends on it.

Proposed resolution

Add the following code to the CE default generator service:

/** @var \Drupal\custom_elements\Entity\EntityCeDisplayInterface $config */
       $config = $storage->create([
         'id' => $id,
         'targetEntityType' => $entity_type_id,
         'bundle' => $bundle,
         'customElementName' => $element_name,
         'mode' => 'default',
         'status' => TRUE,
       ]);

       // These components must be set
       // otherwise it breaks item generation.
       $components = $config->getComponents();
       if (!empty($components)) {
         foreach ($components as $key => $component) {
           $component['name'] = $key;
           $component['is_slot'] = FALSE;
           $config->setComponent($key, $component);
         }
       }
🐛 Bug report
Status

Closed: outdated

Version

3.0

Component

Code

Created by

🇭🇺Hungary junkuncz Budapest

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @junkuncz
  • 🇭🇺Hungary junkuncz Budapest
  • 🇦🇹Austria fago Vienna

    @junkuncz maybe it would be better to make the item-generation code less fragile instead? I mean configuration can become out of sync, when it's exported and people are not updating it.

  • Status changed to Closed: outdated 8 months ago
  • 🇳🇱Netherlands roderik Amsterdam,NL / Budapest,HU

    I believe this can be closed.

    (Just an FYI / self-reminder:)
    First, I moved the foreach ($components) into EntityCeDisplay.php so that the properties are always present, also when loading incomplete config.

    But in the current state of 📌 CustomElementFormatter plugin type for entity_ce_display Active it isn't actually necessary anymore; the warnings/errors for nonexistent array keys are gone. So I'm removing the code from there again.

Production build 0.71.5 2024