getVoteOwner return null when nested paragraphs

Created on 14 May 2025, 2 days ago

Problem/Motivation

I have a paragraph that has nested paragraph which contains the fivestar field.

Steps to reproduce

When creating a node with this paragraph I receive error: Drupal\fivestar\Plugin\Field\FieldType\FivestarItem::getVoteOwner(): Return value must be of type Drupal\Core\Session\AccountInterface, null returned in Drupal\fivestar\Plugin\Field\FieldType\FivestarItem->getVoteOwner()

Proposed resolution

Added patch to check if entity is of type paragraph and return current user.

✨ Feature request
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡·πŸ‡΄Romania sorina.hriban

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

Comments & Activities

  • Issue created by @sorina.hriban
  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia
             if ($entity instanceof EntityOwnerInterface) {
    -          return $entity->getOwner();
    +          $owner = $entity->getOwner();
    +          if (is_null($owner) && $entity instanceof ParagraphInterface) {
    +            return \Drupal::currentUser();
    +          }
    +          return $owner;
             }

    If an entity type implements the EntityOwnerInterface, it must have a getOwner() method, and that getOwner() method must return a UserInterface. NULL is not a valid return value for getOwner(). See https://api.drupal.org/api/drupal/core!modules!user!src!EntityOwnerInter...

    So the issue here is that the Paragraphs module does not return the proper value from getOwner().

    Regardless, adding code to special-case paragraph entities would not be an acceptable solution.

Production build 0.71.5 2024