FiveStarItem presumes existence of isPublished

Created on 22 July 2021, almost 4 years ago
Updated 9 August 2023, over 1 year ago

Problem/Motivation

The postSave function in fivestaritem.php presumes that a call to isPublished() is valid, but this function is not present in all entities returned from getEntity() (aka FieldableEntityInterface). The signal that isPublished is valid is implementing EntityPublishedInterface, which is only true in stock Drupal for entities (such as Node, Media) derived from EditorialContentEntityBase.

Proposed resolution

Be more careful in calling isPublished()...

Replace:

if (!empty($target_entity) && $entity->isPublished()) {

with:

    if (!empty($target_entity) &&
      (
        (($entity instanceof EntityPublishedInterface) && $entity->isPublished())
        || (! $entity instanceof EntityPublishedInterface)
      )
    ) {

... so that entities not implementing isPublished are presumed to be published and therefore the vote can be added.

Remaining tasks

The associated patch implements this change, along with a comment describing why it is necessary.

User interface changes

None

API changes

None

Data model changes

None

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom rivimey

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

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.71.5 2024