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
- Use a site without the Taxonomy module, e.g. the
testingorminimalinstall profile. - Install
canvas_entity_reference:drush en canvas_entity_reference - 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 ondrupal:nodeanddrupal: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 whosex-entity-typedoes 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 laterhook_canvas_storable_prop_shape_alter()was not enough to avoid the crash forexample-taxonomy-card, so this may need further investigation. - Add a
GenericModuleTestBasetest 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
Comment #2
anybodyComment #4
zeeshan_khan commentedMoved 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.
Comment #6
zeeshan_khan commentedComment #7
anybodyThank you once again @zeeshan_khan - great!
Comment #8
zeeshan_khan commentedThanks @Julian you are fast! :D
Comment #11
zeeshan_khan commented