Allow XB to be gradually adopted: make XB's viewing (formatter) and editing (`ApiLayoutController::get()`) work with an empty XB field

Created on 4 March 2025, 7 months ago

Overview

Previously reported by โ€ฆ multiple people, but most recently by Gรกbor Hojtsy.

  1. Install Standard install profile
  2. Install experience_builder
  3. Create article node โ€” let's assume it's node 1
  4. Install xb_dev_standard
  5. Go to /node/1 and you'll get not the rendered article but โ€ฆ a fatal error:
    The website encountered an unexpected error. Try again later.
    
    AssertionError: assert($items->count() === 1) in assert() (line 30 of modules/contrib/experience_builder/src/Plugin/Field/FieldFormatter/NaiveComponentTreeFormatter.php).
    Drupal\experience_builder\Plugin\Field\FieldFormatter\NaiveComponentTreeFormatter->viewElements(Object, 'en') (Line: 91)
    Drupal\Core\Field\FormatterBase->view(Object, 'en') (Line: 275)
    Drupal\Core\Entity\Entity\EntityViewDisplay->buildMultiple(Array) (Line: 340)
    Drupal\Core\Entity\EntityViewBuilder->buildComponents(Array, Array, Array, 'full') (Line: 24)
    Drupal\node\NodeViewBuilder->buildComponents(Array, Array, Array, 'full') (Line: 282)
    Drupal\Core\Entity\EntityViewBuilder->buildMultiple(Array) (Line: 239)
    โ€ฆ
    Drupal\Core\DrupalKernel->handle(Object) (Line: 21)
    
  6. Try to edit this article in XB, by navigating to /xb/node/1/editor, which will not lead to a working XB UI, but to:

Both of these make trying XB, or gradually adopting it a very unfriendly (and even frightening) experience on existing content.

Proposed resolution

The crash in point 5 is caused by \Drupal\experience_builder\Plugin\Field\FieldFormatter\NaiveComponentTreeFormatter::viewElements() requiring a non-empty XB field.

The crash in point 6 is caused by \Drupal\experience_builder\Controller\ApiLayoutController::get() having a similar assumption.

User interface changes

No more crashes.

โœจ Feature request
Status

Active

Version

0.0

Component

Page builder

Created by

๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

Live updates comments and jobs are added and updated live.
  • Usability

    Makes Drupal easier to use. Preferred over UX, D7UX, etc.

Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024