Error if content type do not exist

Created on 18 January 2023, almost 2 years ago
Updated 27 January 2023, almost 2 years ago

Problem/Motivation

I get an error if I remove a existing content type in my dashboard:

Error: Call to a member function getDescription() on null in Drupal\dashboards\Plugin\Dashboard\AddContentMenu->buildRenderArray() (line 86 of modules/contrib/dashboards/src/Plugin/Dashboard/AddContentMenu.php).

Ex:
Warning: Undefined array key "push_notifications" in Drupal\dashboards\Plugin\Dashboard\AddContentMenu->buildRenderArray() (line 87 of modules/contrib/dashboards/src/Plugin/Dashboard/AddContentMenu.php).

Steps to reproduce

Create a dashboard, add "Add content block", then remove a content type and try to access to your dashboard

Proposed resolution

In the controller (src/Plugin/Dashboard/addContentMenu.php) line 84, add a condition:

        if(isset($types[$bundle])){ /* the condition*/
          $items[] = [
            'url' => Url::fromRoute('node.add', ['node_type' => $bundle]),
            'title' => $bundleInfo[$bundle]['label'],
            'description' => ['#markup' => $types[$bundle]->getDescription()],
          ];
        }

Thanks!

🐛 Bug report
Status

Fixed

Version

2.1

Component

Code

Created by

🇪🇸Spain julian_esimaginacion

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