Problem/Motivation

In #3117291: Element::isEmpty() should check for #weight property a new way of checking whether a block is empty was introduced: before this, a block was considered empty if it only had a key of '#cache' set.
It was possible to return '#attached' and inject libraries etc into block content.

Ref https://github.com/drupal/drupal/commit/c3f6ce5cc04d7dc99ccc2eeebf72819d...

Steps to reproduce

* Make a block plugin that returns '#attached' only
* block will not be rendered

Proposed resolution

I'll work on a patch. As a workaround set a '#dummy' key in your block plugin

Remaining tasks

  • make a patch

User interface changes

API changes

Data model changes

Release notes snippet

Comments

miiimooo created an issue. See original summary.

miiimooo’s picture

Issue summary: View changes
miiimooo’s picture

Status: Active » Needs review
StatusFileSize
new1.2 KB

Attached a simple patch that just reverts the check for '#attached'

I haven't looked at the tests yet.

Status: Needs review » Needs work

The last submitted patch, 3: block_empty-3333858-2.patch, failed testing. View results

miiimooo’s picture

StatusFileSize
new2.8 KB

This patch also includes fixes for the "faulty" tests introduced by the commit

cilefen’s picture

Status: Needs work » Needs review
miiimooo’s picture

Unless there is a good reason for the change this needs to go in to 10.0.x and 10.1.x too

larowlan’s picture

Yep this needs to go all the way back to 9.5 from 10.1

larowlan’s picture

Status: Needs review » Reviewed & tested by the community

  • catch committed 943b8f72 on 10.0.x
    Issue #3333858 by miiimooo, larowlan: Blocks that have #attached set...

  • catch committed de66aa93 on 10.1.x
    Issue #3333858 by miiimooo, larowlan: Blocks that have #attached set...

  • catch committed 8929ebe8 on 9.5.x
    Issue #3333858 by miiimooo, larowlan: Blocks that have #attached set...
catch’s picture

Status: Reviewed & tested by the community » Fixed

This makes sense, wondering if we need a more generalised concept of not-content render array keys, but not for here. Committed/pushed to 10.1.x, cherry-picked to 10.0.x and 9.5.x, thanks!

Status: Fixed » Closed (fixed)

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