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
- Install 8.0.x with the Standard profile.
- Visit
/admin/structure/views/view/files/edit/page_1
. - Next to "Fields", click "Add".
- Type "operation" in the search and select "Operation links".
- Use the default options and save the field.
- Save the View.
- Visit
/admin/content/files
. Confirm that the View is displayed correctly so long as there is no content on the site. - Add an article node with an image attachment.
- 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.
Comment | File | Size | Author |
---|---|---|---|
#26 | interdiff-method-name.txt | 635 bytes | xjm |
#26 | vdc-2491875-26.patch | 2.97 KB | xjm |
#23 | 2491875-22.patch | 2.98 KB | alexpott |
#23 | 18-22-interdiff.txt | 3.36 KB | alexpott |
#19 | drupal_2491875_18.patch | 2.32 KB | Xano |
Comments
Comment #1
joachim CreditAttribution: joachim commentedComment #3
joachim CreditAttribution: joachim commentedWhoops.
Comment #5
joachim CreditAttribution: joachim commentedComment #7
joachim CreditAttribution: joachim commentedClearly suffering from a deficiency of brain today.
Comment #8
dawehnerIts sad that operations are bound to the list class, but there is no way around that at the moment.
Comment #9
tstoecklerI think it would be more elegant to use
hasListBuilderClass()
here.Comment #10
joachim CreditAttribution: joachim commentedAh, I hadn't seen that method. Done.
Comment #13
tstoecklerAwesome, thanks!
Comment #14
jibranWe 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.
Comment #15
andypostThis 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
That's strange that operations require list builder.
Suppose handler should build operations without dependency on list builder.
Comment #16
joachim CreditAttribution: joachim commented> 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.
Comment #17
XanoThe 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.
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 ofEntityListBuilderInterface
, do we explicitly disallow other APIs to directly invoke the hook?I'm working on the tests.
Comment #18
andypostyep, not a good idea
PS:
EM::getListBuilder()
should throwInvalidPluginDefinitionException
if no list builder defined, so comment and term could be used for testsComment #19
XanoComment #20
XanoIt already does that. See
EntityManager::getHandler()
. It's not documented onEntityMananagerInterface
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.Comment #21
xjmMarking #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.
Comment #22
xjmAlso @alexpott and I agreed on making this an RC target.
Comment #23
alexpottComment #24
xjm(Removing accidentally copied line from the summary.)
Comment #25
tim.plunkettSeems 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.
Comment #26
xjmJust using the more explicit method name, no added tests.
Comment #27
andypostTest for comments added in #2604618: Views operations dropbuttons do not work with Comment because it does not specify a list builder
Comment #28
dawehnerWe already have integration test coverage for the generic functionality:
\Drupal\views\Tests\Handler\FieldEntityOperationsTest
, IMHO wedon't need integration test coverage for every single bit.
Comment #29
catchCommitted/pushed to 8.0.x, thanks!