Fix fatal error when cloning fields without referencedEntities() method

Problem/Motivation

When cloning entities, the cloneReferencedEntities() method assumes that every entity field provides the referencedEntities() method. However, some contributed field types (e.g., IconFieldItemList from ui_icons_field) do not implement this method, causing a fatal error:

Error: Call to undefined method Drupal\ui_icons_field\Plugin\Field\FieldType\IconFieldItemList::referencedEntities()

Proposed resolution

Add a method_exists() check before calling referencedEntities() in DeepCloningTrait::cloneReferencedEntities(). If the method does not exist, the field is skipped to avoid fatal errors.

Testing instructions

  • Enable the ui_icons_field module.
  • Add an Icon field to an entity type used in Section Library.
  • Clone a section/template that contains this field.
  • Verify that the cloning completes without errors and that other entity reference fields are still cloned as expected.

Notes

This change maintains backward compatibility and only skips fields that do not support referencedEntities().

Edited by Roman Salo

Merge request reports

Loading