Comments

joachim created an issue. See original summary.

Sonal.Sangale’s picture

Assigned: Unassigned » Sonal.Sangale
Sonal.Sangale’s picture

Status: Active » Needs review
StatusFileSize
new649 bytes

Given it a try!

Please review and suggest modifications if required.

Sonal.Sangale’s picture

Assigned: Sonal.Sangale » Unassigned
eojthebrave’s picture

Status: Needs review » Needs work

Hey 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?

joachim’s picture

It'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.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

chx’s picture

I 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.

chx’s picture

Version: 8.3.x-dev » 8.2.x-dev
Priority: Normal » Major
Issue summary: View changes
Status: Needs work » Needs review
berdir’s picture

Fields 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.

berdir’s picture

Status: Needs review » Needs work
andypost’s picture

Title: no docs on possible values of $operation in hook_entity_field_access() » Add docs on possible values of $operation in hook_entity_field_access()
chx’s picture

Status: Needs work » Needs review
StatusFileSize
new746 bytes

Thanks 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.

andypost’s picture

+++ b/core/lib/Drupal/Core/Entity/entity.api.php
@@ -1845,7 +1845,8 @@ function hook_entity_operation_alter(array &$operations, \Drupal\Core\Entity\Ent
+ *   \Drupal\Core\Entity\EntityAccessControlHandlerInterface::fieldAccess()

it makes sense to add @see

markdorison’s picture

Added @see reference.

andypost’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Documentation

Looks good, not sure a bug

chx’s picture

Looks good, not sure a bug

Well, 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.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 15: add_docs_on_possible-2747177-15.patch, failed testing.

andypost’s picture

Status: Needs work » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed 71ca377 to 8.3.x and 2495e7b to 8.2.x and f01ff77 to 8.1.x. Thanks!

  • alexpott committed 71ca377 on 8.3.x
    Issue #2747177 by markdorison, chx, Sonal.Sangale, andypost, joachim,...

  • alexpott committed 2495e7b on 8.2.x
    Issue #2747177 by markdorison, chx, Sonal.Sangale, andypost, joachim,...

  • alexpott committed f01ff77 on 8.1.x
    Issue #2747177 by markdorison, chx, Sonal.Sangale, andypost, joachim,...

Status: Fixed » Closed (fixed)

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