getUrl() on null when adding a node

Created on 28 August 2024, 3 months ago
Updated 29 August 2024, 3 months ago

Problem/Motivation

2024/08/28 10:37:55 [error] 50517#50517: *11574821 FastCGI sent in stderr: "PHP message: Uncaught PHP Exception Error: "Call to a member function getUrl() on null" at /xxx/web/modules/contrib/paragraphs_bootstrap_carousel/src/Plugin/Field/FieldFormatter/ParagraphsBootstrapCarouselFormatter.php line 473"

Steps to reproduce

Add a node with one carousel image

Proposed resolution

471 if (!empty($field_link)) {
$linkField = $entity->get($field_link);
+ if (!empty($linkField->first())) {
$item->image_link = $linkField->first()->getUrl()->toString();
+ }
$item->caption_title = $linkField->title;

Remaining tasks

User interface changes

API changes

Data model changes

๐Ÿ› Bug report
Status

Closed: won't fix

Version

2.0

Component

Code

Created by

๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand scrypter

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @scrypter
  • Assigned to vimal_nadar
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia vimal_nadar

    Let me work on this.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia sanket.tale

    Not able to reproduce. Can you add proper steps to reproduce this issue.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia vimal_nadar

    I installed the Paragraphs Bootstrap Carousel module, added the field to a content type, and successfully uploaded an image without encountering the previously mentioned error. Please see the attached screenshot below.

  • Issue was unassigned.
  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand scrypter

    Unfortunately I don't have steps to reproduce. It is a site migrated to D10 from D7 and collections became paragraphs. It worked fine on local dev and on initial testing. Then when copied to another instance for -st testing, the error appeared.
    My investigation did not discover why $entity->get() failed. With this line $linkField = $entity->get($field_link); the assumption on the next line is that $linkField is in good shape. So whether the check for !empty() is really necessary is debatable, I don't think it does any harm, just another line of defense.
    No problem if you want to leave it, sorry I can't provide more useful info.

  • Status changed to Closed: won't fix 3 months ago
  • ๐Ÿ‡ซ๐Ÿ‡ทFrance lazzyvn paris

    It means there is no image in your paragraphs. But image field is required it canโ€™t be empty

Production build 0.71.5 2024