Problem/Motivation

Getting Error on file usage page for default image uploaded on image field.

Steps to reproduce

  1. Upload and set default image for any field.
  2. Check the files in the admin/content/files page
  3. Click the file usage link for the file. the page getting 500 Error

Drupal\Component\Plugin\Exception\PluginNotFoundException: The "default_image" entity type does not exist. in Drupal\Core\Entity\EntityTypeManager->getDefinition() (line 139 of /app/docroot/core/lib/Drupal/Core/Entity/EntityTypeManager.php).

Proposed resolution

- Add a check in "Drupal\views\Plugin\views\field\EntityLabel"'s preRender method to ensure that entity type manager has plugin definition

Remaining tasks

- Update PR with latest 11.x
- Change PR destination to point to 11.x instead of 10.2.x

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

Issue fork drupal-3442346

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

leopathu created an issue. See original summary.

larowlan’s picture

Status: Active » Postponed (maintainer needs more info)
Issue tags: +Bug Smash Initiative

Can you turn on verbose error reporting from admin/config/development/logging and provide the full stack trace? Thanks

leopathu’s picture

Status: Postponed (maintainer needs more info) » Active

Here is the Logs info

The website encountered an unexpected error. Try again later.

Drupal\Component\Plugin\Exception\PluginNotFoundException: The "default_image" entity type does not exist. in Drupal\Core\Entity\EntityTypeManager->getDefinition() (line 139 of core/lib/Drupal/Core/Entity/EntityTypeManager.php).
Drupal\Core\Entity\EntityTypeManager->getHandler('default_image', 'storage') (Line: 192)
Drupal\Core\Entity\EntityTypeManager->getStorage('default_image') (Line: 139)
Drupal\views\Plugin\views\field\EntityLabel->preRender(Array) (Line: 1518)
Drupal\views\ViewExecutable->render() (Line: 199)
Drupal\views\Plugin\views\display\Page->execute() (Line: 1645)
Drupal\views\ViewExecutable->executeDisplay('page_2', Array) (Line: 81)
Drupal\views\Element\View::preRenderViewElement(Array)
call_user_func_array(Array, Array) (Line: 111)
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: 859)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 421)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 240)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 238)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 239)
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: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 50)
Drupal\ban\BanMiddleware->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: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
mingsong’s picture

I couldn't reproduce this error by the following steps on a Drupal 10.2.5 site:

  1. Go to the media overview page (/admin/content/media).
  2. Add a new media by clicking the link(button) 'Add media'.
  3. In the 'New media' page(/media/add), add an Image media.
  4. In the 'New image' page(/media/add/image), fill in all required fields, such as name, image file(uploaded).
  5. Save this new image media.
  6. Go to the file overview page(/admin/content/files)
  7. Click the file link uploaded by that image media above
  8. The image file open as expected. No error
leopathu’s picture

@Mingsong It is happening only for default image uploaded on image fields.
For example: Set a default image for any image field. and see the image file usage in the admin/content/files page. then you can get it.

larowlan’s picture

This looks like the views entity label plugin on this view is conflating the file usage type with an entity type

The call to getStorage needs to check hasDefinition first

mingsong’s picture

A new test to reproduce this error in 10.2.x branch.

https://git.drupalcode.org/project/drupal/-/merge_requests/7660/diffs

mingsong’s picture

Status: Active » Needs work

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

mohit_aghera’s picture

Issue summary: View changes

@Mingsong can you please update the PR with latest 11.x and change the destination for 11.x
I've pushed the fix on the branch.
There seems one test case failure, however this is failing on 11.x head as well (on my local).
So not sure if this issue's change is the root cause of this one.

Other test case written for bug is passing on local.

Keeping this in needs work until we update the PR and pipeline is green.

mingsong’s picture

Thanks @Mohit for the fix.

The origin branch is based on the 10.2.x branch and there are some conflicts if targeting 11.x branch.

So I created a another branch based on the 11.x branch and a new MR targeting the 11.x branch.

https://git.drupalcode.org/project/drupal/-/merge_requests/7752

We need to fix this issue for all active branches(10.2.x, 10.3.x and 11.x)

Cheers,

mingsong’s picture

Status: Needs work » Needs review
mingsong’s picture

Issue summary: View changes
kanchan bhogade’s picture

StatusFileSize
new282.4 KB
new36.18 KB
new261.72 KB
new36.14 KB

Hi
I've tested MR !7752 on Drupal 10.2 and 11.x
MR is applied cleanly...

Test Result:
No error for the default image uploaded on the image field on the file usage page and the "File Uses Page" is displayed.

Adding Screenshots for references
RTBC+1

Keeping in "Needs review" for Code verification

smustgrave changed the visibility of the branch 3442346-default-image-usage to hidden.

smustgrave’s picture

Version: 10.2.x-dev » 11.x-dev
Status: Needs review » Needs work
1) Drupal\Tests\file\Functional\FileImageTest::testDefaultImageFile
Behat\Mink\Exception\ExpectationException: Current response status code is 500, but 200 expected.
/builds/issue/drupal-3442346/vendor/behat/mink/src/WebAssert.php:888
/builds/issue/drupal-3442346/vendor/behat/mink/src/WebAssert.php:145
/builds/issue/drupal-3442346/core/modules/file/tests/src/Functional/FileImageTest.php:105
/builds/issue/drupal-3442346/vendor/phpunit/phpunit/src/Framework/TestResult.php:729
ERRORS!
Tests: 1, Assertions: 9, Errors: 1.

Shows test coverage.

Left a comment on the MR though.

mingsong’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Much better to me, thanks for taking care of that.

larowlan’s picture

Status: Reviewed & tested by the community » Needs work

Nice one folks, couple of comments on the MR

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

pradhumanjain2311’s picture

@larowlan i didn't understand how to remove getValue call but i tried to reduce a loop please review.

larowlan’s picture

Left a comment clarifying my point @pradhumanjain2311 - thanks

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.