BlockComponent::checkRequirements() should disallow any block plugins whose definition declares it requires certain contexts

Created on 22 April 2025, 2 days ago

Overview

Until πŸ“Œ Handle block contexts Active is done, XB won't pass contexts to block plugins.

… but \Drupal\experience_builder\Plugin\ExperienceBuilder\ComponentSource\BlockComponent::checkRequirements() does not yet check that!

This means XB users may be placing block components that don't actually work as expected, which will certainly result in bug reports.

Proposed resolution

  1. Add a block plugin to the xb_test_block module with optional contexts
  2. Add a block plugin to the xb_test_block module with required contexts
  3. … and whichever other permutations may exist
  4. Update BlockComponent::checkRequirements() to disallow contexts (or required contexts only?) β€” requires investigating how block plugins actually use these
  5. Update \Drupal\Tests\experience_builder\Kernel\Plugin\ExperienceBuilder\ComponentSource\BlockComponentTest::testDiscovery() expectations

User interface changes

/admin/appearance/component/status will start saying that some blocks use contexts, and are hence excluded from use in XB.

πŸ“Œ Task
Status

Active

Version

0.0

Component

Component sources

Created by

πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @wim leers
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί
  • First commit to issue fork.
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts
  • Pipeline finished with Failed
    1 day ago
    Total: 751s
    #480613
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    A refreshingly easy test to update. Those are a bit hard to find in XB πŸ™ˆ

  • Pipeline finished with Failed
    1 day ago
    Total: 231s
    #480620
  • Pipeline finished with Failed
    1 day ago
    Total: 342s
    #480622
  • Pipeline finished with Failed
    1 day ago
    Total: 1475s
    #480626
  • Pipeline finished with Failed
    1 day ago
    Total: 1932s
    #480661
  • Pipeline finished with Failed
    about 24 hours ago
    Total: 3510s
    #480813
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Thanks, this looks superb!

    A refreshingly easy test to update. Those are a bit hard to find in XB πŸ™ˆ

    That's literally what we're working to improve β†’ .

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Note: this means that XB will start refusing ViewsBlocks whose Views use arguments, because:

              // Look for arguments and expose them as context.
              foreach ($display->getHandlers('argument') as $argument_name => $argument) {
                /** @var \Drupal\views\Plugin\views\argument\ArgumentPluginBase $argument */
                if ($context_definition = $argument->getContextDefinition()) {
                  $this->derivatives[$delta]['context_definitions'][$argument_name] = $context_definition;
                }
              }
    

    β€” \Drupal\views\Plugin\Derivative\ViewsBlock::getDerivativeDefinitions()

    And that's a good thing, because those blocks would not work as expected in XB today, because πŸ“Œ Handle block contexts Active is not implemented yet. πŸ‘

Production build 0.71.5 2024