Cannot use object of type Feed as array

Created on 2 November 2023, about 1 year ago
Updated 18 November 2023, about 1 year ago

Problem/Motivation

Error when cloning an entity with a feed_item attached to it.

Error: Cannot use object of type Drupal\feeds\Entity\Feed as array in Drupal\feeds\Plugin\Field\FieldType\FeedsItem->setValue() (line 39 of /web/modules/contrib/feeds/src/Plugin/Field/FieldType/FeedsItem.php) #0

Logically, the feed_item field should not be cloned as it isn't part of the feed. However FeedsItem seems to only partially implement EntityReferenceItem, not catering for the option to pass an object.

Steps to reproduce

Versions

drupal/feeds dev-3.x 884264d Aggregates RSS/Atom/RDF feeds, imports CSV files and more.
drupal/feeds_tamper 2.0.0-beta2 Modify feeds data before it gets saved.
drupal/entity_clone 2.0.0-beta4 Add a clone action for all entities.

Upload an entity and attempt to clone it.

Proposed resolution

EntityReferenceItem has a conditional for objects

  public function setValue($values, $notify = TRUE) {
    if (isset($values) && !is_array($values)) {
      // If either a scalar or an object was passed as the value for the item,
      // assign it to the 'entity' property since that works for both cases.
      $this->set('entity', $values, $notify);
    }
    else {
      parent::setValue($values, FALSE);

FeedsItem does not

  public function setValue($values, $notify = TRUE) {
    if (isset($values['url']) && empty($values['url'])) {
      // Set url explicitly to NULL to prevent validation errors.
      $values['url'] = NULL;
    }
    return parent::setValue($values, $notify);
  }

The first conditional is required.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

🇦🇺Australia interlated

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024