Originating from https://git.drupalcode.org/project/drowl_canvas/-/work_items/3615406
Summarized with the help of AI:

Problem/Motivation

Installing canvas_entity_reference on a site without the Taxonomy module (and likewise Node) fails. The module only depends on canvas:canvas, but it ships example and test SDCs that reference taxonomy_term and node via x-entity-type. When Canvas generates the Component config entities for these SDCs during the install, it calculates their dependencies. That fails because the referenced entity type does not exist:

Drupal\Component\Plugin\Exception\PluginNotFoundException: The "taxonomy_term" entity type does not exist.

web/core/lib/Drupal/Core/Entity/EntityTypeManager.php:171
web/modules/contrib/canvas/src/PropExpressions/StructuredData/FieldPropExpression.php:139
web/modules/contrib/canvas/src/PropExpressions/StructuredData/ReferenceFieldTypePropExpression.php:217
web/modules/contrib/canvas/src/PropSource/StaticPropSource.php:639
web/modules/contrib/canvas/src/Plugin/Canvas/ComponentSource/JsonSchemaPropsComponentSourceBase.php:181
web/modules/contrib/canvas/src/Plugin/Canvas/ComponentSource/SingleDirectoryComponent.php:120
web/core/lib/Drupal/Core/Plugin/PluginDependencyTrait.php:71
...
web/modules/contrib/canvas/src/Entity/Component.php:194
web/modules/contrib/canvas/src/ComponentSource/ComponentSourceManager.php:238
web/modules/contrib/canvas/src/ComponentSource/ComponentSourceManager.php:124
web/modules/contrib/canvas/src/Hook/ComponentSourceHooks.php:95
web/core/lib/Drupal/Core/Extension/ModuleInstaller.php:257

The failing component is sdc.canvas_entity_reference.example-taxonomy-card (prop category: items.x-entity-type: taxonomy_term). Other bundled components reference taxonomy_term or node as well: test-multi-nodes, test-bundle-filter, test-node-ref, test-node-id.

This also breaks GenericModuleTestBase tests of every module that depends on canvas_entity_reference, because those run on the testing profile without Taxonomy and Node.

Steps to reproduce

  1. Use a site without the Taxonomy module, e.g. the testing or minimal install profile.
  2. Install canvas_entity_reference: drush en canvas_entity_reference
  3. The install fails with the exception above.

Alternatively, a generic module test reproduces it:

namespace Drupal\Tests\canvas_entity_reference\Functional;

use Drupal\Tests\system\Functional\Module\GenericModuleTestBase;

/**
 * @group canvas_entity_reference
 */
class GenericCanvasEntityReferenceTest extends GenericModuleTestBase {

  protected function assertHookHelp(string $module): void {}

}

Tested with Drupal core 11.4.11, Canvas 1.12.0, Canvas Entity Reference 1.0.4.

Proposed resolution

  • Move the example and test SDCs (group "Entity Reference Tests") into a test module (e.g. tests/modules/canvas_entity_reference_test), or into an optional submodule that depends on drupal:node and drupal:taxonomy. They should not be in the component library of production sites anyway.
  • Make the prop shape matching more robust: in EntityReferenceHooks::storablePropShapeAlter() / EntityReferenceShapeMatcher, don't map props whose x-entity-type does not exist (EntityTypeManagerInterface::hasDefinition()). Canvas then flags the component as incompatible instead of crashing. Note: in a downstream module, marking such props as unstorable in a later hook_canvas_storable_prop_shape_alter() was not enough to avoid the crash for example-taxonomy-card, so this may need further investigation.
  • Add a GenericModuleTestBase test to catch this.

Remaining tasks

  • Decide between a test module and an optional submodule for the example components
  • Patch / MR
  • Tests

User interface changes

The example / test components no longer show up in the Canvas component library on production sites.

API changes

None.

Data model changes

None.

Comments

anybody created an issue. See original summary.

anybody’s picture

Issue summary: View changes

  • zeeshan_khan committed 2e64d582 on issue/3636953-skip-example-components-without-deps
    Issue #3636953: Fix install crash on sites without node/taxonomy...
zeeshan_khan’s picture

Moved the example and test components (the "Entity Reference Tests" group) into a new optional submodule, canvas_entity_reference_examples, which depends on node, taxonomy, media, and block_content. It's not installed by default, so the main module no longer references those entity types during install.

Also added a hasDefinition() check in EntityReferenceShapeMatcher so a component referencing an entity type that isn't installed is treated as incompatible instead of crashing, and added a GenericModuleTestBase test to catch this regression.

MR: https://git.drupalcode.org/project/canvas_entity_reference/-/merge_reque...

AI-assisted: Claude was used to investigate this issue and draft the fix; reviewed and tested manually before submitting.

  • zeeshan_khan committed f617727c on issue/3636953-skip-example-components-without-deps
    Issue #3636953: Fix install crash on sites without node/taxonomy...
zeeshan_khan’s picture

Status: Active » Needs review
anybody’s picture

Status: Needs review » Reviewed & tested by the community

Thank you once again @zeeshan_khan - great!

zeeshan_khan’s picture

Thanks @Julian you are fast! :D

  • zeeshan_khan committed ce41c0a2 on issue/3636953-skip-example-components-without-deps
    Add hook_help() to fix GenericModuleTestBase failure
    
    The new...

  • zeeshan_khan committed c07e1f9c on 1.0.x
    Issue #3636953: Fix install crash on sites without node/taxonomy
    
zeeshan_khan’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.