Problem/Motivation

ContextualLinksHelper::addLinks() opens with:

public function addLinks(array &$renderElement, string $location, string $displayId, ?array $viewElement = NULL): void {
  assert(in_array($location, ['block', 'page', 'view'], TRUE));

But Drupal\views\Plugin\Block\ViewsExposedFilterBlock::build() calls into this path with the location 'exposed_filter':

// ViewsExposedFilterBlock::build()
$this->addContextualLinks($output, 'exposed_filter');

ViewsBlockBase::addContextualLinks() forwards that $block_type straight through to addLinks() as $location. With zend.assertions=1, this throws:

AssertionError: assert(in_array($location, ['block', 'page', 'view'], TRUE))
in assert() (line 79 of core/modules/views/src/ContextualLinksHelper.php).
Drupal\views\ContextualLinksHelper->addLinks()
Drupal\views\Plugin\Block\ViewsBlockBase->addContextualLinks()
Drupal\views\Plugin\Block\ViewsExposedFilterBlock->build()
Drupal\block\BlockViewBuilder::preRender()

Steps to reproduce

  • Install Drupal 11.4.x with the standard profile (assertions enabled — the default outside production, e.g. via development.services.yml / SymfonyRequirements).
  • Enable the Views and Contextual Links modules.
  • Create (or use) a view with an exposed filter and an "Exposed form in block" enabled, or use any view display that exposes its filters as a block.
  • Place the view's "Exposed form: …" block in a visible region (e.g. Header) at Structure → Block layout.
  • Visit any page where that block renders, as a user with permission to see contextual links (e.g. an admin).
  • Result: AssertionError / WSOD on every page that renders the block.
  • Expected: The page renders and the exposed-filter block shows its contextual links, as it did prior to 11.4.

Proposed resolution

Add 'exposed_filter' to the allowlist in the assertion so it matches the locations the method already supports:

assert(in_array($location, ['block', 'page', 'view', 'exposed_filter'], TRUE));

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3592878

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

ltrain created an issue. See original summary.

quietone’s picture

Version: 11.4.x-dev » main

Hi, Issues for Drupal core should be targeted to the 'main' branch, our primary development branch. Changes are made on the main branch first, and are then back ported as needed according to the Core change policies. This is also mentioned on the version section of the list of issue fields documentation. The version the problem was discovered on should be stated in the issue summary Problem/Motivation section. Thanks.

phenaproxima’s picture

Status: Active » Reviewed & tested by the community

This works, and would fix Drupal CMS's CI pipeline (we currently have to patch around this).

phenaproxima’s picture

  • amateescu committed c42c8879 on 11.4.x
    fix: #3592878 ContextualLinksHelper::addLinks() assertion rejects the '...

  • amateescu committed ac253bb5 on 11.x
    fix: #3592878 ContextualLinksHelper::addLinks() assertion rejects the '...

  • amateescu committed 87c1c03d on main
    fix: #3592878 ContextualLinksHelper::addLinks() assertion rejects the '...
amateescu’s picture

Version: main » 11.4.x-dev
Status: Reviewed & tested by the community » Fixed

I think this is a small bugfix that doesn't require test coverage (per #2972776: [policy, no patch] Better scoping for bug fix test coverage).

Committed and pushed 87c1c03df12 to main and ac253bb5976 to 11.x and c42c8879c0b to 11.4.x. Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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