Undefined array key "status" with nested paragraphs

Created on 30 December 2022, almost 2 years ago
Updated 14 July 2023, over 1 year ago

Problem/Motivation

Hi,

I'm getting this warning:

Warning: Undefined array key "status" in Drupal\Core\Entity\ContentEntityBase->Drupal\Core\Entity\{closure}() (line 1013 of /var/www/html/web/core/lib/Drupal/Core/Entity/ContentEntityBase.php)

Steps to reproduce

  1. Create a site with translations actived.
  2. Create a paragraph with a field referencing other paragraph('s).
  3. Create a CT with a field referencing the created paragraph.
  4. Create a node.
  5. Check warnings.

Proposed resolution

I think it's simple. Can we controle if the "status" key exists to avoid the warning?

I found the warning in the next two cases that I've just controled:

public function getTranslationLanguages($include_default = TRUE) {
    $translations = array_filter($this->translations, function ($translation) {
      if (array_key_exists('status', $translation)) {
        return $translation['status'];
      }
    });
    unset($translations[LanguageInterface::LANGCODE_DEFAULT]);

    if ($include_default) {
      $translations[$this->defaultLangcode] = TRUE;
    }

    // Now load language objects based upon translation langcodes.
    return array_intersect_key($this->getLanguages(), $translations);
  }
public function postSave(EntityStorageInterface $storage, $update = TRUE) {
    parent::postSave($storage, $update);

    // Update the status of all saved translations.
    $removed = [];
    foreach ($this->translations as $langcode => &$data) {
      if (array_key_exists('status', $data)) {
        if ($data['status'] == static::TRANSLATION_REMOVED) {
          $removed[$langcode] = TRUE;
        }
        else {
          $data['status'] = static::TRANSLATION_EXISTING;
        }
      }
    }
    $this->translations = array_diff_key($this->translations, $removed);

    // Reset the new revision flag.
    $this->newRevision = FALSE;

    // Reset the enforcement of the revision translation affected flag.
    $this->enforceRevisionTranslationAffected = [];
  }

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

💬 Support request
Status

Postponed: needs info

Version

9.5

Component
Entity 

Last updated about 16 hours ago

Created by

🇪🇸Spain semapo82 Barcelona

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