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

stBorchert created an issue. See original summary.

stborchert’s picture

Status: Active » Needs review
StatusFileSize
new1.6 KB

The attached patch filters the build list using Element:children(), so anything should be safe.

miro_dietiker’s picture

Priority: Normal » Major

Major since the added plugin system broke some sites, see reports in other issue.

Someone plz review.

stborchert’s picture

Issue summary: View changes
berdir’s picture

Looks 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.

primsi’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

+1 to #5

steffenr’s picture

Assigned: Unassigned » steffenr

I'll reroll the patch against the latest DEV version and also change the variable naming to $build.

steffenr’s picture

Assigned: steffenr » Unassigned
Status: Needs work » Needs review
StatusFileSize
new1.99 KB

Attached you find the updated/ rerolled patch.

Please review.

  • Primsi committed c60eddc on 8.x-1.x authored by SteffenR
    Issue #2867069 by stBorchert, SteffenR, Berdir: Error: Call to a member...
primsi’s picture

Status: Needs review » Fixed

As per discussion with @miro_dietiker we skip tests. Thanks.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.