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 givenStack 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
- Install Drupal 11.3.3
- Install and enable:
- Webform
- Webform Access
- Canvas
- Add a Webform Access–related block to a Canvas layout
- Open the Canvas UI
Result:
An unexpected error has occurred while rendering the component's form.
Error 500PHP 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
Comment #2
alabandit commentedComment #3
liam morlandThanks for the report. Please put your fix into an issue fork and merge request.
Comment #4
bdh676 commentedLooks like there is an issue for this logged over at Canvas: https://www.drupal.org/project/canvas/issues/3570822
Comment #5
cilefen commented