Version

  • Drupal CMS: 11.3.3
  • Webform: 6.3.0-beta7
  • Webform Access: 6.3.0-beta7
  • Canvas module: 1.1.0
  • PHP: 8.5

Issue Summary

When a Webform Access–related block is rendered inside the Canvas layout editor (API context), Drupal throws a fatal error:

Drupal\Core\Render\Element::isEmpty(): 
Argument #1 ($elements) must be of type array, null given

Stack trace shows the error originates from:

Drupal\Core\Render\Element::isEmpty()
called from:
Drupal\canvas\Plugin\Canvas\ComponentSource\BlockComponent->renderComponent()

Debugging confirms that the block’s build() method is returning NULL instead of a render array.

In Drupal 11, Element::isEmpty() requires a strict array type. Returning NULL now results in a fatal type error.

Steps to Reproduce

  1. Install Drupal 11.3.3
  2. Install and enable:
  3. Webform
  4. Webform Access
  5. Canvas
  6. Add a Webform Access–related block to a Canvas layout
  7. Open the Canvas UI

Result:

An unexpected error has occurred while rendering the component's form.
Error 500

PHP error:

Argument #1 ($elements) must be of type array, null given

Expected Behavior

Block build() methods should always return a render array (even if empty), e.g.:

return [];

They should never return NULL.

Actual Behavior

Under certain conditions (likely missing context or API rendering mode), the Webform Access block returns NULL.

This worked in Drupal 10 but causes a fatal error in Drupal 11 due to stricter typing.

Suggested Fix

Ensure the block plugin’s build() method always returns an array:

Example defensive fix:

public function build() {
  $build = parent::build();

  if ($build === NULL) {
    return [];
  }

  return $build;
}

Or ensure any conditional early exits return [] instead of NULL.

Additional Notes

This appears to occur when blocks are rendered in an API context (Canvas editor), where route/context data may be unavailable.

The block should defensively handle missing context and still return a valid render array.

Issue fork webform-3573777

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

alabandit created an issue. See original summary.

alabandit’s picture

Issue summary: View changes
liam morland’s picture

Version: 6.3.0-beta7 » 6.3.x-dev

Thanks for the report. Please put your fix into an issue fork and merge request.

bdh676’s picture

Looks like there is an issue for this logged over at Canvas: https://www.drupal.org/project/canvas/issues/3570822

cilefen’s picture

Status: Active » Postponed (maintainer needs more info)
Issue tags: +Possible duplicate

mark_fullmer made their first commit to this issue’s fork.

mark_fullmer’s picture

Status: Postponed (maintainer needs more info) » Needs review

My analysis of this is that this should be considered a shortcoming in the implementation of WebformAccessGroupEntityBlock::build(), since the parent method expects a renderable array to be returned. Therefore, this module should return an empty array in the circumstances where it is currently returning NULL. I've created a merge request that stages this change, and have updated the issue status to "Needs review."

See also commentary in the Drupal Canvas issue: https://www.drupal.org/project/canvas/issues/3570822#comment-16564546

liam morland’s picture

Issue tags: -Possible duplicate

Yes, the parent class is clear that ::build() returns array.

liam morland’s picture

Status: Needs review » Fixed

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.