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;
    }

Issue fork domain-3254743

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

nielsva created an issue. See original summary.

nvaken’s picture

Status: Active » Needs review
agentrickard’s picture

Status: Needs review » Needs work

This looks like a cleaner (or more updated version of the current code).

It also looks like domain/tests/src/Functional/DomainContextTest.php is unfinished. That's where we should probably test this.

mably’s picture

Is it still a problem? It it is the case, can we have a MR on 2.0.x please?

mably’s picture

Version: 8.x-1.x-dev » 2.0.x-dev
Status: Needs work » Needs review

Rebased.

mably’s picture

Priority: Major » Normal

mably’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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