Closed (fixed)
Project:
Bibliography & Citation
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
4 Apr 2020 at 06:34 UTC
Updated:
12 Aug 2020 at 06:39 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
antongp commentedYou mean on reference entity view page like
bibcite/reference/12345? It's expected behavior. Use$operationparameter and add a condition on it.Comment #3
lomasr commentedComment #4
lomasr commentedThanks antongp for the reply. I meant /bibcite/reference/add/{type} page. Sorry about that.
Comment #5
antongp commentedThere is separate
hook_ENTITY_TYPE_create_access()hook in Drupal for access handling on entity creation.Comment #6
rbrandon commented@antongp The I think the issue here is that hook_ENTITY_TYPE_access is called on the /bibcite/reference/add/{type} page and hook_ENTITY_TYPE_create_access should be called instead. Is that correct Lomas?
Comment #7
lomasr commented@rbrandon Hi, Thanks for the reply, yes its correct.
Comment #8
u_tiwari commentedThe bug here is that when one tries to add a Reference Entity via the form path
/bibcite/reference/add/{type}:First,
\Drupal\Core\Entity\EntityAccessControlHandler::createAccessis checked and related create Access hooks are invoked which are likehook_ENTITY_TYPE_create_access(). This is the correct behavior.But then the control also goes to any hooks which are like
hook_ENTITY_TYPE_accesswhich means $entity->access() is also invoked during form render and I found it is called to checkdeleteoperation#access. This is an unexpected behaviour and also is not consistent with Nodes.Example to understand, why this is a problem - Let's say we have a custom access check wrapper around bibcite's access check and we use
hook_ENTITY_TYPE_create_accessfor create related access wrappers andhook_ENTITY_TYPE_accessfor other operations such as update/delete/etc .Assuming this works correctly, one can write code like
$reference_entity->id()in his custom access checker which is invoked fromhook_ENTITY_TYPE_access, as by this time entity is not new and id is available, but due to the bug - this will be called for first-time entity creation during form render, so this would definitely fail or break as id() will be called on null.I am debugging this and will be creating a patch for a fix.
Comment #9
u_tiwari commentedThis fixes the issue, this is inspired as to how Node handle's this check. NodeForm let's
Drupal\Core\Entity\EntityForm::actionshandle the entity->isNew() check and then works on it if delete is present, I think we can follow the same here. Please review.Comment #12
antongp commented