When using imagefield_tokens in conjunction with Layout Builder, I get a whitescreen with this error:

Drupal\Component\Plugin\Exception\ContextException: The entity context is not a valid context. in Drupal\Component\Plugin\ContextAwarePluginBase->getContextDefinition() (line 118 of core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php).

Drupal\Core\Plugin\ContextAwarePluginBase->getContextDefinition('entity') (Line: 53)
Drupal\Core\Plugin\ContextAwarePluginBase->getContext('entity') (Line: 181)

I am rendering a Media reference field in layout builder. The view mode for that media type is using imagefield_tokens. Steps to replicate are nasty. I'm going to post a patch that fixes my problem and should look pretty harmless.

Comments

danflanagan8 created an issue. See original summary.

danflanagan8’s picture

This patch just adds a try/catch block and fixes this bug for me.

danflanagan8’s picture

Status: Active » Needs review
ysamoylenko’s picture

Status: Needs review » Reviewed & tested by the community

Thank you for the patch.
It will be applied soon.

ysamoylenko’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.