WSOD when no `domain` context value is available in Domain condition

Created on 16 December 2021, over 3 years ago
Updated 16 August 2025, 7 days ago

Drupal Version

9.2.10

Domain module version

8.x-1.0-beta6

Expected Behavior

Domain condition should actually derive the domain if there is no `domain` context value available.

Actual Behavior

The following exception is thrown, since the existence of the value is checked by `getContextValue()` (see: https://git.drupalcode.org/project/domain/-/blob/8.x-1.x/domain/src/Plug...) which will throw a exception if the value is absent.

Drupal\Component\Plugin\Exception\ContextException: The 'entity:domain' context is required and not present. in Drupal\Core\Plugin\Context\Context->getContextValue() (line 73 of core/lib/Drupal/Core/Plugin/Context/Context.php).

Steps to reproduce

Not sure when the domain context value should actually be present. I noticed that it is absent when trying to evaluate the condition in a `html` preprocess with the following code:

    $block = $this->entityTypeManager->getStorage('block')->load('BLOCK_ID');
    if (!$block) {
      return $variables;
    }

    $visibilityConditions = $block->getVisibilityConditions();
    if (!is_iterable($visibilityConditions)) {
      return $variables;
    }

    $visible = TRUE;
    foreach ($visibilityConditions as $visibilityCondition) {

      if ($visibilityCondition->evaluate()) {
        continue;
      }

      $visible = FALSE;
    }
🐛 Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

🇳🇱Netherlands aken.niels@gmail.com

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024