Problem/Motivation

Currently, the [paragraph:parent] token returns the parent property of the paragraph regardless of whether the parent entity (or specifically, the current revision) still references the paragraph - for example, perhaps it was referenced in an older revision and is removed in the current revision (but the paragraph hasn't been deleted via the orphans cleanup batcher).

Proposed resolution

It could be argued that the expected behavior is that the token only returns a value if the parent's default revision still references the paragraph. Attached patch runs this check for parent tokens via a hook_tokens_alter().

Comments

bgilhome created an issue. See original summary.

bgilhome’s picture

We can get the parent's field name to check for the paragraph reference instead of checking all referenced entities - updated patch attached. Also fix the Token findWithPrefix() call.

d70rr3s’s picture

This can be an issue for programmatically created paragraphs and any code relying on tokens that is implemented during the create phase of the entity lifecycle, e.g.: using tokens on hook_entity_insert, at that point the parent entity can be set but the reference will not since depends on the paragraph ID.