API page: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21...
This says:
> https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21...
But https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Access%21... doesn't have that information.
As this is security related , the complete lack of information deserves a major priority.
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | add_docs_on_possible-2747177-15.patch | 1.29 KB | markdorison |
Comments
Comment #2
Sonal.Sangale commentedComment #3
Sonal.Sangale commentedGiven it a try!
Please review and suggest modifications if required.
Comment #4
Sonal.Sangale commentedComment #5
eojthebraveHey Sonal, I'm curious where you got the values 'add', 'edit', and 'delete' from? Looking at the code it's not immediately obvious to me where that's coming from.
hook_entity_field_access() is invoked once inside of https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21..., and passed the $operations parameter from that that method has been given. The documentation there says this will likely be one of 'view', or 'edit'.
This is called once here:
\Drupal\views\Plugin\views\field\Field::access() with 'view' as the operation.
And then here as well \Drupal\Core\Field\FieldItemList::access(), so far the only usages of FieldItemList::access() I've been able to track down thus far have 'edit', and 'view' as the operations.
Were you able to track down example usages of the 'add' and 'delete' argument?
Comment #6
joachim commentedIt's maybe worth mentioning that in Entity API on D7, the $operation value passed to entity_access() was essentially arbitrary. You could pass in anything, and equally, your own entity type's implementation of the access system could respond to anything. Entity API's access system was just a broker in the middle that passed the $operation along without caring about it.
Though I don't know whether this is also true on D8.
Comment #8
chx commentedI searched for fieldAccess which is calls this hooks and multiple tests and Views call fieldAccess('view'). Some tests (UserAccessControlHandlerTest) also use edit and delete. It's possible that's all. create access usually has a different way since there's no entity yet.
Note the _entity_access key / relevant EntityAccessCheck uses different names -- it uses view, update and delete but also arbitrary strings.
Comment #9
chx commentedComment #10
berdirFields basically just use view and edit. They have on concept of adding or deleting, since everything happens while editing.
But yes, essentially it's just a string that's passed through to the hooks and method on the field classes. But unlike entity access, were special operations are quite often used, I think that's pretty rare for field level access. I don't think I ever had a use case for that.
Comment #11
berdirComment #12
andypostComment #13
chx commentedThanks Berdir for the quick answer. I found that fieldAccess $operation is documented with these exact strings you mentioned. And I agree with the original that keeping this docs in one place is a good idea.
Comment #14
andypostit makes sense to add @see
Comment #15
markdorisonAdded @see reference.
Comment #16
andypostLooks good, not sure a bug
Comment #17
chx commentedWell, what do I know. A few years ago I would have filed this as a critical issue because it's security related and it's insane that entity access uses update while field access uses edit. That's the kind of thing that leads to security holes.
But that's the old kind of thinking where I was relentlessly chasing security and often choosing security over user/developer experience.
However, the community no longer cares about security as much (proof: #2628870: Access result caching per user(.permissions) does not check for correct user is still not addressed) and that is fine as well so feel free to mark this as a minor feature request. What do I know? What do I care? I wrote my field access hook for Smartsheet and so I am done.
Unfollowing.
Comment #19
andypostComment #20
alexpottCommitted and pushed 71ca377 to 8.3.x and 2495e7b to 8.2.x and f01ff77 to 8.1.x. Thanks!