Problem/Motivation
Hey.
After updating Paragraphs from 8.x-1.0 to the latest dev we got the following error:
Error: Call to a member function bundle() on null in Drupal\paragraphs\ParagraphViewBuilder->buildMultiple() (line 21 of modules/contrib/paragraphs/src/ParagraphViewBuilder.php).
It seems like there isn't any check about what's in $build_list (as it's done in EntityViewBuilder).
We are using something similar to the code below to add the rendered output of some paragraphs to our Solr index.
Steps to reproduce
<?php
// Guess we have an entity with "field_paragraphs" containing multiple items ...
$paragraphs = $entity->field_paragraphs->referencedEntities();
$first_entity = reset($paragraphs);
$bundle = $first_paragraph->bundle();
$view_builder = \Drupal::entityTypeManager()->getViewBuilder($first_paragraph->getEntityTypeId());
// Create the build list.
$build = $view_builder->viewMultiple($paragraphs, 'teaser');
// Render items.
$rendered_output = (string) $this->getRenderer()->renderPlain($build);
?>
Proposed resolution
Loop through valid children of $build_list only.
Remaining tasks
* create patch
Comments
Comment #2
stborchertThe attached patch filters the build list using Element:children(), so anything should be safe.
Comment #3
miro_dietikerMajor since the added plugin system broke some sites, see reports in other issue.
Someone plz review.
Comment #4
stborchertComment #5
berdirLooks fine but $paragraph is imho not a good variable name, and yes, $value was even worse. Let's just use $build.
A test would also be useful.
Comment #6
primsi commented+1 to #5
Comment #7
steffenrI'll reroll the patch against the latest DEV version and also change the variable naming to $build.
Comment #8
steffenrAttached you find the updated/ rerolled patch.
Please review.
Comment #10
primsi commentedAs per discussion with @miro_dietiker we skip tests. Thanks.