WSOD if referenced entity has no mapping

Created on 29 May 2023, about 1 year ago
Updated 31 May 2023, about 1 year ago

Problem/Motivation

SchemaDotOrgJsonLdBuilder:getSchemaPropertyFieldItem handles entity references, but it assumes it should always be a Schema.org mapping for the referenced entity:

        /** @var \Drupal\schemadotorg\SchemaDotOrgMappingStorageInterface $mapping_storage */
        $mapping_storage = $this->entityTypeManager->getStorage('schemadotorg_mapping');
        $node_mapping = $mapping_storage->loadByEntity($node);
        $node_schema_property = $node_mapping->getSchemaPropertyMapping('title') ?? 'name';

But... $mapping_storage->loadByEntity($node) can be NULL if the entity has no mapping (isEntityMapped)

public function loadByEntity(EntityInterface $entity): ?SchemaDotOrgMappingInterface {
    if (!$this->isEntityMapped($entity)) {
      return NULL;
    }
}

A check should be added to avoid WSODs

Steps to reproduce

- Have a Node entity reference another Node entity (of a different bundle) on an entity reference field.
- The parent Node should have a schema.org mappping
- The child (referenced) Node shouldn't have a schema.org mapping.
- Access the node, a WSOD happens.

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ͺπŸ‡ΈSpain idiaz.roncero Madrid

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

Comments & Activities

Production build 0.69.0 2024