- Issue created by @RandalV
- Merge request !30Issue #3541778 by randalv: It's possible a referenced paragraph does not exist, resulting in a WSOD → (Open) created by RandalV
It's possible a referenced paragraph does not exist, resulting in a WSOD with this error:
Error: Call to a member function createDuplicate() on null in Drupal\layout_builder_at\Plugin\Field\FieldWidget\LayoutBuilderCopyWidget->cloneEntity() (line 344 of /.../web/modules/contrib/layout_builder_at/src/Plugin/Field/FieldWidget/LayoutBuilderCopyWidget.php).
I'm not sure how this came to be, but one of our nodes had a block with a referenced paragraph that doesn't seem to exist.
Lines 338 to 344 of the LayoutBuilderCopyWidget contain this code:
$values = $clone->get($definition->getName())->getValue();
if (!empty($values)) {
foreach ($values as $value) {
/** @var \Drupal\Core\Entity\EntityInterface $reference */
/** @var \Drupal\Core\Entity\EntityInterface $reference_clone */
$reference = \Drupal::service('entity_type.manager')->getStorage($target_type)->load($value['target_id']);
$reference_clone = $reference->createDuplicate();
I would suggest replacing it with:
/** @var \Drupal\Core\Entity\EntityInterface[] $references */
$references = $clone->get($definition->getName())->referencedEntities();
if (!empty($references)) {
foreach ($references as $reference) {
$reference_clone = $reference->createDuplicate();
This ensures only existing references can be cloned, and `createDuplicate` can't be called on a null-value.
I'll create a patch/MR
N/A
N/A
N/A
Active
3.0
Code