Update logic for getOwner to account for entities that allow NULL value

Created on 18 May 2021, about 3 years ago
Updated 19 March 2024, 3 months ago

Problem/Motivation

The getOwner method on the EntityOwnerInterface can return NULL or an int. In the case where an entity implements the EntityOwnerInterface but does not return an int, comparisons that don't take into account type say that the object is owned by the anonymous user.

Steps to reproduce

Easiest way to reproduce is probably to add a paragraph to a block, because Paragraphs attached to Blocks wouldn't have an OwnerId.
1. Create a new paragraph type with one public and one private field. The private field can either use the "Private" plugin or use the Custom Access plugin with "view own XYZ" selected for anonymous users.
2. Create a new block type that has one field - a paragraph reference
3. Create a block of the block type just made and place it on the page using block layout
4. Log out and look at the page.

Expected results: You don't see the private field on the paragraph
Actual result: You do see the private field.

Proposed resolution

Simple: Change a couple of these: $entity->getOwnerId() == $account->id() to $entity->getOwnerId() === $account->id(). NULL !== 0.

Remaining tasks

Review and merge

🐛 Bug report
Status

RTBC

Version

1.0

Component

Code

Created by

🇺🇸United States mariacha1

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024