Problem/Motivation

Opening the Storage overview page, the following error shows up:

Error: Call to a member function hasCanonical() on null in Drupal\storage\Controller\StorageController->viewCanonicalAccess() (line 123 of modules/contrib/storage/src/Controller/StorageController.php).
call_user_func_array(Array, Array) (Line: 84)

Issue fork storage-3533906

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

steveg. created an issue. See original summary.

abhishek_gupta1 made their first commit to this issue’s fork.

abhishek_gupta1’s picture

Status: Active » Needs review

@steveg., I have fixed the issue and created MR, please review it once. thanks

steveg.’s picture

I've checked if is working after the patch you've provided. But again when opening the Storage overview page I get an error. I have installed Drupal core 10.5.1 and Storage Entities 1.4.0-rc1.

Error: Call to a member function id() on null in Drupal\storage\Controller\StorageController->viewCanonicalAccess() (line 127 of modules/contrib/storage/src/Controller/StorageController.php).
call_user_func_array(Array, Array) (Line: 84)
Drupal\Core\Access\CustomAccessCheck->access(Object, Object, Object, NULL)
call_user_func_array(Array, Array) (Line: 160)
Drupal\Core\Access\AccessManager->performCheck('access_check.custom', Object) (Line: 136)
Drupal\Core\Access\AccessManager->check(Object, Object, NULL, 1) (Line: 93)
Drupal\Core\Access\AccessManager->checkNamedRoute('entity.storage.canonical', Array, NULL, 1) (Line: 832)
Drupal\Core\Url->access(NULL, 1) (Line: 132)
Drupal\Core\Field\Plugin\Field\FieldFormatter\StringFormatter->viewElements(Object, 'nl') (Line: 91)
Drupal\Core\Field\FormatterBase->view(Object, 'nl') (Line: 268)
Drupal\Core\Entity\Entity\EntityViewDisplay->buildMultiple(Array) (Line: 257)
Drupal\views\Entity\Render\EntityFieldRenderer->buildFields(Array) (Line: 143)
Drupal\views\Entity\Render\EntityFieldRenderer->render(Object, Object) (Line: 873)
Drupal\views\Plugin\views\field\EntityField->getItems(Object) (Line: 1195)
Drupal\views\Plugin\views\field\FieldPluginBase->advancedRender(Object) (Line: 238)
template_preprocess_views_view_field(Array, 'views_view_field', Array)
call_user_func_array('template_preprocess_views_view_field', Array) (Line: 261)
Drupal\Core\Theme\ThemeManager->render('views_view_field', Array) (Line: 490)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 248)
Drupal\Core\Render\Renderer->render(Array) (Line: 1796)
Drupal\views\Plugin\views\field\FieldPluginBase->theme(Object) (Line: 769)
Drupal\views\Plugin\views\style\StylePluginBase->elementPreRenderRow(Array)
call_user_func_array(Array, Array) (Line: 113)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 886)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 431)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 248)
Drupal\Core\Render\Renderer->render(Array) (Line: 708)
Drupal\views\Plugin\views\style\StylePluginBase->renderFields(Array) (Line: 574)
Drupal\views\Plugin\views\style\StylePluginBase->renderGrouping(Array, Array, 1) (Line: 462)
Drupal\views\Plugin\views\style\StylePluginBase->render() (Line: 2177)
Drupal\views\Plugin\views\display\DisplayPluginBase->render() (Line: 1593)
Drupal\views\ViewExecutable->render() (Line: 201)
Drupal\views\Plugin\views\display\Page->execute() (Line: 1690)
Drupal\views\ViewExecutable->executeDisplay('storage_page_list', Array) (Line: 81)
Drupal\views\Element\View::preRenderViewElement(Array)
call_user_func_array(Array, Array) (Line: 113)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 886)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 431)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 248)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 238)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 637)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 231)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 128)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 186)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 53)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 116)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 90)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 263)
Drupal\shield\ShieldMiddleware->bypass(Object, 1, 1) (Line: 130)
Drupal\shield\ShieldMiddleware->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 741)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
mandclu’s picture

Status: Needs review » Postponed (maintainer needs more info)

I'm using a fresh install of Drupal 11.2.4 and Storage dev-1.4.x. I am able to successfully access the storage overview page without or without existing storage entities in the database. Clear steps to reproduce are needed before I can evaluate the proposed changes.

steveg.’s picture

The problem occurs in Drupal 10.5.3 in combination with Storage 4.1, that's the reason why you don't get this error.

When we update from version 1.3.1 to version 4.1 and then go to content and click on Storage data, the error message above appears.

nicxvan’s picture

I hit this locally, but on version 1.3 and it seems to be devel actually:

/**
 * Implements hook_entity_operation().
 */
function devel_entity_operation(EntityInterface $entity) {
    return Drupal::service('class_resolver')
      ->getInstanceFromDefinition(EntityTypeInfo::class)
      ->entityOperation($entity);
}

Triggers:

Error: Call to a member function hasCanonical() on null in Drupal\storage\Entity\Storage->hasLinkTemplate() (line 212 of modules/contrib/storage/src/Entity/Storage.php).

Drupal\devel\EntityTypeInfo->entityOperation() (Line: 93)
devel_entity_operation()

Digging deeper it is happening here in: web/modules/contrib/storage/src/Entity/Storage.php

 $type = \Drupal::entityTypeManager()->getStorage('storage_type')->load($this->bundle());
      if (!$type->hasCanonical()) {
        return FALSE;
      }

A check for type here also fixes the issue.

nicxvan’s picture

Issue summary: View changes
nicxvan’s picture

Status: Postponed (maintainer needs more info) » Needs review

I'm not sure how we got in that state, but I suspect that we have these storage entities in the database still even though I deleted them.

It is possible I imported an older db with them.

glottus’s picture

I just ran into this issue as well, but in this case it is Drupal 11.2.5 with Storage 1.4.0.

This is an existing site built in Drupal 9 or 10, but since upgraded. The addition of Storage is new today.

I created a storage type, gave it several fields, and then attempted to migrate content into it, but got the above error. To try and troubleshoot this, I manually went to /storage/add and created a sample entry and retried the Storage overview page, but with no difference.

Then, following this thread, I applied the proposed fix in MR !20, but still got an error:

Error: Call to a member function id() on null in Drupal\storage\Controller\StorageController->viewCanonicalAccess() (line 127 of modules/contrib/storage/src/Controller/StorageController.php).

This is only the second site I've tried Storage on, and the first had no such issues. The main differences I can think of were that the first (also a long-established site) was probably Drupal 11.2.4 at the time (and still is), and Storage 1.4.0-rc1 (since updated to 1.4.0).

A second attempt (reverting my database and re-adding the module) did seem to help, so still don't know how to recreate this.

[Edited to add] In subsequent tests, I determined that my migration had accidentally set the "type" to a non-existent value in one place and correctly identified my storage type machine name in another. This didn't apparently affect my migration itself, but caused the Storage Content page to choke. Finding and removing the erroneous "type" line in my migration YML allowed it to run and populate as expected, loading when I visited that page.