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.

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