EntityReferenceItem::isEmpty returns TRUE when field contains value

Created on 27 July 2018, about 6 years ago
Updated 11 December 2023, 10 months ago

In the Workflow module , the Entity Type workflow_transition can have attached fields using the Field UI.
When saving such an entity, the module checks if any attached fields are empty. This works fine for an field, but not with an or a file field.
For those fields, the function EntityReferenceItem::isEmpty is called, but this returns Always TRUE. See below code.

IMO there is some error in the function EntityReferenceItem::isEmpty.

This is the code:

class WorkflowTransition extends ContentEntityBase implements WorkflowTransitionInterface {
// ...
  /**
   * Check if anything has changed in this transition.
   *
   * @return bool
   */
  protected function isEmpty() {
    if ($this->getToSid() != $this->getFromSid()) {
      return FALSE;
    }
    if ($this->getComment()) {
      return FALSE;
    }
    $fields = WorkflowManager::getAttachedFields('workflow_transition', $this->bundle());
    /** @var \Drupal\Core\Field\Entity\BaseFieldOverride $field */
    foreach ($fields as $field_name => $field) {
      if (!$this->{$field_name}->isEmpty()) {   // <-- here , image and file return Always TRUE
        return FALSE;
      }
    }
    return true;
  }

}
🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Entity reference 

Last updated 7 days ago

No maintainer
Created by

🇳🇱Netherlands johnv

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

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