Problem/Motivation
After upgrading to Drupal 11, I see the following error while rendering a View, including in the Views preview area.
TypeError: Drupal\Core\Render\Renderer::doRender(): Argument `#1` ($elements) must be of type array, null given, called in /var/www/web/core/lib/Drupal/Core/Render/Renderer.php on line 222 in Drupal\Core\Render\Renderer->doRender() (line 265 of core/lib/Drupal/Core/Render/Renderer.php).
Drupal\Core\Render\Renderer->render(NULL) (Line: 56)
Drupal\html_title\Plugin\views\field\NodeHtmlTitle->renderText(Array) (Line: 1260)
Drupal\views\Plugin\views\field\FieldPluginBase->advancedRender(Object) (Line: 230)
template_preprocess_views_view_field(Array, 'views_view_field', Array)
...
Steps to reproduce
Only occurs in Drupal 11
- Add an entity reference (node) field to a taxonomy.
- Create a taxonomy term, but do NOT reference any nodes in this field.
- Create a view that is a Taxonomy Term based view.
- Add a relationship to content based on the entity reference field. ("Content referenced from field_test_node_reference")
- Add a contextual filter "Taxonomy term: Term ID" with fixed value of the id of your test term.
- You should now see your term name in the Views preview area.
- Add the Content Title field, using the relationship.
- The view Preview will now crash with a console error!
Proposed resolution
The attached patch uses "empty" to check if the $alter['rendered'] array key exists before passing it to the renderer.
Comments
Comment #2
jessehsComment #3
bhogue commentedI can confirm that I was able to preview/create the view as per the instructions above without any crash/console error.
However, when I went to the page that my view was configured to display on, this error was displayed:
Comment #4
jessehs@bhogue, I was testing with Drupal 11.2.2. Perhaps you are using a dev release. It looks like a fix for this was committed to 11.2.x and 11.3.x recently:
https://www.drupal.org/project/drupal/issues/3524738
However, this patch should still be committed since this code will break again in Drupal 12.
Comment #7
vitaliyb98 commentedThis issue is still relevant. While it can be avoided by enabling "Require this relationship" on the relationship, I recommend applying this fix to prevent unnecessary errors.
I’ve also added a test to cover this fix.
Comment #8
vitaliyb98 commentedMerged into 8.x-1.x, thanks