Warnings can be thrown during plungin cache clears

Created on 17 September 2021, about 3 years ago
Updated 5 July 2023, about 1 year ago

Problem/Motivation

The "issue" is that during certain processes, Drupal will clear various caches and in this process The following code which we have in a few places:

$labels = \Drupal::service('entity_type.repository')->getEntityTypeLabels(TRUE);
$options = $labels[(string) t('Content', [], ['context' => 'Entity type group'])];
// $options is null.

When $options is null we get various warnings when doing array operations on it. It doesn't crash Drupal, but generates a lot of log messages as it throws a PHP Warning.

Steps to reproduce

I'm not entirely sure how/when this is trigged, but some oprations like installing or uninstalling modules generate the warnings

Proposed resolution

We can add a few checks to see if getEntityTypeLabels returns what we expect.

🐛 Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

🇩🇰Denmark googletorp

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.

  • 🇷🇸Serbia holo96

    Steps to reproduce:

    1. Enable Account administration pages in `Interface text language detection` (/admin/config/regional/language/detection)
    2. On your profile edit choose different language from default language.
    3. Flush cache from some admin page
    4. Go to Edit (View might also work) form of some entity using base theme (can be applied if user does not have permission for admin theme)
    5. BanG!

    It is unstable to rely on translations. Patch attached

    Patch does not do anything special. It just relies on machine name of content instead of translation "Content".
    So it should just add stability to module.

  • Status changed to Needs review over 1 year ago
  • 🇷🇸Serbia holo96

    Also I don't think #6 is proper solution... So I've just created new one.

  • Status changed to Needs work about 1 year ago
  • 🇵🇰Pakistan jibran Sydney, Australia

    RE #8: This issue sounds similar to 🐛 Content entity type ids are being gathered in a wrong way Closed: won't fix . Can you please check all the 'entity type label' are defined on your site?

    PR: I think we only see the warning thrown when DynamicEntityReferenceItem::defaultFieldSettings() is called. Let's remove the other changes and check it again.

Production build 0.71.5 2024