TypeError: Drupal\simple_sitemap\Entity\SimpleSitemap::getType()

Created on 7 March 2024, 9 months ago
Updated 19 July 2024, 4 months ago

Problem/Motivation

Get the error during fresh install.
TypeError: Drupal\simple_sitemap\Entity\SimpleSitemap::getType(): Return value must be of type Drupal\simple_sitemap\Entity\SimpleSitemapTypeInterface, null returned in Drupal\simple_sitemap\Entity\SimpleSitemap->getType() (line 131 of /app/docroot/modules/contrib/simple_sitemap/src/Entity/SimpleSitemap.php).

Steps to reproduce

I have done a fresh install and after db updates and during cim step, this issue occurs.

Proposed resolution

more error handling -

public function getType(): SimpleSitemapTypeInterface {
    if ($this->sitemapType === NULL) {
        $type_id = $this->get('type');
        if ($type_id) {
            $type_entity = $this->entityTypeManager()->getStorage('simple_sitemap_type')->load($type_id);
            if ($type_entity) {
                $this->sitemapType = $type_entity;
            } else {
                // Handle case where entity is not found
                throw new \RuntimeException("SimpleSitemapType entity with ID $type_id not found.");
            }
        } else {
            // Handle case where 'type' field is empty
            throw new \RuntimeException("Type field is empty for SimpleSitemap entity.");
        }
    }

    return $this->sitemapType;
}

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Closed: cannot reproduce

Version

4.0

Component

Code

Created by

🇦🇺Australia Nadim Hossain

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