eca_token_load_entity_ref resolves Defined by token names under the wrong plugin ID
Problem/Motivation
EntityLoader::$pluginId (modules/content/src/Service/EntityLoader.php:71)
is an uninitialized typed property that is only ever set by loadEntity(),
whose $pluginId parameter defaults to 'eca_token_load_entity'
(EntityLoader.php:304).
Consumers do not all pass it:
EntityExists.php:50passes'eca_entity_exists'explicitly — correct.LoadEntity.php:147passes nothing — so it falls back to the default, which happens to match its own plugin IDeca_token_load_entity, and is correct by coincidence.LoadEntityRefextendsLoadEntityand inherits that same call, but its plugin ID iseca_token_load_entity_ref— so it silently resolves under the wrong plugin ID.
The form and the runtime therefore disagree about the token name. The form
builds the companion token name from the plugin's own ID via
buildTokenName() (src/Plugin/ECA/PluginFormTrait.php:28-30) and so tells
the user to create:
eca_token_load_entity_ref_fromwhile runtime resolution, going through the service's defaulted $pluginId,
reads:
eca_token_load_entity_fromSteps to reproduce
- Add an Entity: load entity reference (
eca_token_load_entity_ref) action to an ECA model. - Set From to "Defined by token".
- Follow the on-screen instruction and create a token named
eca_token_load_entity_ref_from. - Execute the model.
Result: the value is not picked up — the runtime looks for
eca_token_load_entity_from.
Expected: the token name the form asks for is the token name the runtime
reads.
Proposed resolution
Make the plugin ID explicit rather than defaulted. LoadEntity should pass its
own $this->getPluginId() (or equivalent) into loadEntity(), so
LoadEntityRef inherits the correct value automatically, matching the pattern
EntityExists already follows.
Consider also removing the default from loadEntity()'s $pluginId parameter
so a missing argument becomes a hard error rather than a silent
misattribution, and initializing EntityLoader::$pluginId so the uninitialized
typed property cannot be read before it is set.
This affects the three keys EntityLoader supplies — from, entity_type
and langcode — for eca_token_load_entity_ref.
Remaining tasks
- Pass the plugin ID explicitly from
LoadEntity - Decide whether to drop the parameter default and initialize the property
- Add test coverage asserting the form-declared token name is the one the runtime resolves, for all three keys
User interface changes
None.
Data model changes
None.
Related: #3590375 (closed) fixes the config-schema half of the "Defined by token"
problem for these same keys. This issue is independent of that one: even with
the schema corrected, the _eca_token path on eca_token_load_entity_ref
resolves the wrong token name.
Found while auditing the sentinel surface for #3590375 (closed).
AI-Generated: Yes (Used OpenCode to audit the _eca_token sentinel surface
across ECA while working on #3590375 (closed); this defect was found incidentally and
all file and line references were verified against the 3.1.x source.)