Problem/Motivation
NodeAccessControlHandlerInterface::writeGrants()
has the following documentation note:
Note: Don't call this function directly from a contributed module. Call node_access_acquire_grants() instead.
There are two problems with this:
node_access_acquire_grants()
no longer exists; it has been replaced withNodeAccessControlHandlerInterface::acquireGrants()
.- We shouldn't have a public method for something that, essentially, doesn't seem to be intended as public.
The method is simply a wrapper for:
$grants = $this->acquireGrants($node);
$this->grantStorage->write($node, $grants, NULL, $delete);
The only usages are in node_access_rebuild()
(which logically should be a method on the handler or storage anyway):
$grants = $this->acquireGrants($node);
$this->grantStorage->write($node, $grants, NULL, $delete);
And in Node::postSave()
:
if ($this->isDefaultRevision()) {
\Drupal::entityManager()->getAccessControlHandler('node')->writeGrants($this, $update);
}
Proposed resolution
Is there any reason not to just remove the method? It seems like a mostly-dead misdirection that is only tested implicitly and that explicitly says it's not supposed to be used. Since it would be a narrowing of the API, but a BC break, I think it would be okay to deprecate the method in 8.0.x for removal in 9.x.
Remaining tasks
- Discuss.
- Patch.
User interface changes
None.
API changes
NodeAccessControlHandlerInterface::writeGrants()
is deprecated.
Comment | File | Size | Author |
---|---|---|---|
#9 | deprecate-2473021-9.patch | 5.93 KB | amitgoyal |
#5 | deprecate-2473021-5.patch | 6.14 KB | jcnventura |
#5 | interdiff.txt | 2.32 KB | jcnventura |
Comments
Comment #1
xjmComment #2
xjmThere is also a bogus reference to
node_access_write_grants()
in the hook_node_access_records() documentation.Comment #3
xjmComment #4
jcnventura CreditAttribution: jcnventura commentedI agree, and it certainly doesn't hurt to deprecate it. At least it will serve to tell anyone that uses it that they shouldn't (which is already the case, if the documentation is right).
Comment #5
jcnventura CreditAttribution: jcnventura commentedSlightly improved version with some documentation clean-up.
Now the question seems to be if the same warning to not use NodeGrantStorageInterface::write() directly also means that we should deprecate it or remove the warning. That function isn't a simple wrapper like this one, so I'd be strongly against deprecating it (and besides, what's the benefit of a storage interface if you can't write to it??).
Comment #6
Mile23#2473041: Deprecate node_access_grants() and move its functionality to NodeAccessControlHandler is basically postponed on this issue.
Retesting to see if it still doesn't explode.
Not really in scope here, but if contrib shouldn't call this, then it shouldn't be part of the interface.
Is there really no place these services are injected into the entity?
Comment #8
Mile23Comment #9
amitgoyal CreditAttribution: amitgoyal commentedReroll of #5.
Comment #10
amitgoyal CreditAttribution: amitgoyal commentedComment #12
jcnventura CreditAttribution: jcnventura commentedRetesting, as #9 is correct.
As to the comments in #6:
1. It's only correcting the comment to point to the right place. Moving this method out of the interface is as referred, out of scope.
2. No. These services are not injected. There's one use each of these services and they both use the same code. The only thing I found, two steps above in the class hierarchy, is that we could replace \Drupal::entityManager() with $this->entityManager() (which in turn would call \Drupal::entityManager(), thus adding one extra stack call).
Comment #14
jcnventura CreditAttribution: jcnventura commentedRequesting some triage on this. It's mostly documentation, but it also contains some preparation for removing the code in writeGrants, by copying it's logic to the places where it's used.
Comment #15
jcnventura CreditAttribution: jcnventura commentedAnd the tag.
Comment #16
catchShould it be deprecated or @internal?
Comment #17
xjmI think deprecating it is correct.
Comment #18
Mile23Comment #19
naveenvalechaPatch looks good to be in.
Comment #21
catchCommitted/pushed to 8.1.x, thanks!