Problem/Motivation

Language context missing in Block Deriver definition.


As we were updating our site from 8.9 to 9.2.7 we noticed this module was throwing the following exception:

Drupal\Component\Plugin\Exception\ContextException: Assigned contexts were not satisfied: language in Drupal\Core\Plugin\Context\ContextHandler->applyContextMapping() (line 145 of /DRUPAL_ROOT/core/lib/Drupal/Core/Plugin/Context/ContextHandler.php).

So, we needed to dig in and fix the problem because this exception was blocking the rendering of our content.

Steps to reproduce

Simply enable this module for one of your content types under Drupal 9.2.x environment, and try to view/render it, you should have the aforesaid exception.

Proposed resolution

The problem we found is the missing language context on the deriver class (src/Plugin/Derivative/TextLongFieldTocBlockDeriver.php) on the getDerivativeDefinitions method. We had to add the language context using the context repository service.

Remaining tasks

We should also considere to replace the context entry on @Block annotation under src/Plugin/Block/TextLongFieldTocBlock.php with context_definitions since it was deprecated since Drupal 8.7

User interface changes

None

API changes

None

Data model changes

None

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

hawkeye.twolf created an issue. See original summary.

hawkeye.twolf’s picture

adaltavo’s picture

Issue summary: View changes
e0ipso’s picture

Status: Active » Reviewed & tested by the community

This looks great!

e0ipso’s picture

I left some minor comments.

hawkeye.twolf’s picture

RTBC from me! Be sure to credit @adaltavo with the commits.

e0ipso’s picture

Status: Reviewed & tested by the community » Fixed

This looks good. Merging.

  • e0ipso committed 8091c63 on 8.x-1.x authored by hawkeye.twolf
    Issue #3244723 by hawkeye.twolf, e0ipso, adaltavo: Fix missing language...

  • e0ipso committed 5e39a5d on 2.x authored by hawkeye.twolf
    Issue #3244723 by hawkeye.twolf, e0ipso, adaltavo: Fix missing language...

Status: Fixed » Closed (fixed)

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