Problem/Motivation

Drupal\views\EntityViewsData adds an 'Operations links' field to all entity types.

However, the Views field handler for Operations links relies on the entity type having a list builder declared:

  public function render(ResultRow $values) {
    $entity = $this->getEntity($values);
    $operations = $this->entityManager->getListBuilder($entity->getEntityTypeId())->getOperations($entity);

Thus if an entity type doesn't declare a list builder in its annotation, this field is available on views of the entity, but crashes the view:

Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException: The "file" entity type did not specify a list_builder handler. in Drupal\Core\Entity\EntityManager->getHandler() (line 360 of /code/core/lib/Drupal/Core/Entity/EntityManager.php).

Steps to reproduce

  1. Install 8.0.x with the Standard profile.
  2. Visit /admin/structure/views/view/files/edit/page_1.
  3. Next to "Fields", click "Add".
  4. Type "operation" in the search and select "Operation links".
  5. Use the default options and save the field.
  6. Save the View.
  7. Visit /admin/content/files. Confirm that the View is displayed correctly so long as there is no content on the site.
  8. Add an article node with an image attachment.
  9. Visit /admin/content/files again. You will receive an error.

Workaround

If you encounter this error with a files view, visit /admin/structure/views, edit the view, and remove the operation links field. Your view will start working again.

Proposed resolution

In the handler, only supply the operation links if a list builder is available.

Note that this also will affect the Views integration of other entity types not currently specifying a list builder even though they should have them, e.g. comment. See #1986606: Convert the comments administration screen to a view.

Why is this an RC target

If you select the entity operations field on a view of comments or files you get WSOD.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joachim’s picture

Status: Active » Needs review
FileSize
1.08 KB

Status: Needs review » Needs work
joachim’s picture

Status: Needs work » Needs review
FileSize
1.08 KB

Whoops.

Status: Needs review » Needs work
joachim’s picture

Status: Needs work » Needs review
FileSize
1.12 KB

Status: Needs review » Needs work
joachim’s picture

Status: Needs work » Needs review
FileSize
1.12 KB

Clearly suffering from a deficiency of brain today.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Its sad that operations are bound to the list class, but there is no way around that at the moment.

tstoeckler’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/views/src/EntityViewsData.php
@@ -152,13 +152,18 @@ public function getViewsData() {
+    $list_builder_class = $this->entityType->getHandlerClass('list_builder');
+    if ($list_builder_class) {

I think it would be more elegant to use hasListBuilderClass() here.

joachim’s picture

Status: Needs work » Needs review
FileSize
1.06 KB

Ah, I hadn't seen that method. Done.

Status: Needs review » Needs work

Status: Needs work » Needs review
tstoeckler’s picture

Status: Needs review » Reviewed & tested by the community

Awesome, thanks!

jibran’s picture

We have the same issue in #1986606: Convert the comments administration screen to a view as well for comment. We are using dropbutton instead of operations links field there.

andypost’s picture

This actually should be tested (NW)
Looks we need to update docblocks hook_entity_operation & its alter to point that this hooks works only for entity types with list builder defined, otoh ...
There's EntityListBuilder that should be used when entity annotation "list_builder" is empty
Looks that require Berdir's mention

+++ b/core/modules/views/src/EntityViewsData.php
@@ -152,13 +152,17 @@ public function getViewsData() {
+    if ($this->entityType->hasListBuilderClass()) {
+      // The handler for entity operations needs the entity list builder; only
+      // provide it if there is one.

That's strange that operations require list builder.
Suppose handler should build operations without dependency on list builder.

joachim’s picture

> That's strange that operations require list builder.
Suppose handler should build operations without dependency on list builder.

I agree it seems weird, but dawehner said in #8 that that's not possible.

> There's EntityListBuilder that should be used when entity annotation "list_builder" is empty

Some entity types actively don't want a list builder, not even a default.

Xano’s picture

The reason that operations are tied to list builders, is that in #1839516: Introduce entity operation providers it was decided we couldn't introduce a new type of entity handler to do this, because it would break existing list builders. That's why some entity types have to jump through hoops to get operations links.

Looks we need to update docblocks hook_entity_operation & its alter to point that this hooks works only for entity types with list builder defined, otoh ...

Maybe we should indeed. However, there is no standard to this kind of documentation. We always considered hooks to be part of our APIs. In Drupal 8 we seem to be moving to a point of view where we consider interfaces APIs and hooks are mere implementation details of those APIs. Next to that: if we document hook_entity_operation*() as being an implementation detail of EntityListBuilderInterface, do we explicitly disallow other APIs to directly invoke the hook?

I'm working on the tests.

andypost’s picture

if we document hook_entity_operation*() as being an implementation detail of EntityListBuilderInterface, do we explicitly disallow other APIs to directly invoke the hook?

yep, not a good idea

PS: EM::getListBuilder() should throw InvalidPluginDefinitionException if no list builder defined, so comment and term could be used for tests

Xano’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
1.26 KB
2.32 KB
Xano’s picture

PS: EM::getListBuilder() should throw InvalidPluginDefinitionException if no list builder defined, so comment and term could be used for tests

It already does that. See EntityManager::getHandler(). It's not documented on EntityMananagerInterface and I don't think this is good behavior, because a missing list builder does not make the plugin definition itself invalid, but that's another issue.

xjm’s picture

Title: EntityViewsData adds Operations links to all entities, which won't work if the entity type has no list builder » EntityViewsData adds Operations links to all entities, which won't work if the entity type has no list builder, leading to WSOD on some views
Issue summary: View changes
Related issues: +#2587551: Selecting Operation Links for File Type View throws an Exception, +#1986606: Convert the comments administration screen to a view

Marking #2587551: Selecting Operation Links for File Type View throws an Exception as a duplicate of this issue. @alexpott's patch over there includes an update function. This patch includes tests. Let's combine forces!

Also adding information to the summary to make this issue easier to find in search.

xjm’s picture

Issue tags: +VDC, +rc target

Also @alexpott and I agreed on making this an RC target.

alexpott’s picture

xjm’s picture

Issue summary: View changes

(Removing accidentally copied line from the summary.)

tim.plunkett’s picture

Seems like we should have an actual test of the functionality (the \Drupal\views\Plugin\views\field\EntityOperations class itself) and not just of views data.
Also, why not put a hasListBuilderClass() check in there? Seems like that should exist regardless.

xjm’s picture

Just using the more explicit method name, no added tests.

andypost’s picture

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

We already have integration test coverage for the generic functionality: \Drupal\views\Tests\Handler\FieldEntityOperationsTest, IMHO we
don't need integration test coverage for every single bit.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.0.x, thanks!

  • catch committed bad2aea on 8.0.x
    Issue #2491875 by joachim, xjm, Xano, alexpott: EntityViewsData adds...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.