I would like grant access to create a new entity in an IEF field widget based on some business logic, for example, to allow a particular user to create a new content type only when editing a node form with this IEF field, which they would otherwise not have access to create.
This can be made possible by passing some contextual information to InlineEntityFormBase::canAddNew() and InlineEntityFormBase::getCreateBundles(), which then gets passed to EntityAccessControlHandler::createAccess().
Then I could use hook_entity_create_access() and hook_ENTITY_TYPE_create_access() to evaluate this context and optionally grant access.
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | ief_parent_context_v3.patch | 5.19 KB | holo96 |
Issue fork inline_entity_form-3043511
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3043511-context-3.x
changes, plain diff MR !154
- 3.x
compare
- 2.0.x
changes, plain diff MR !75
Comments
Comment #2
joelstein commentedHere's a patch which does the trick and allows me to do something like this:
Comment #3
geek-merlinThanks for proposing that API addition! I really like the way you think and approach this.
As of the direction, i'm split: This looks elegant, but the bigger part in me deems this an abuse of the access API (Note to me: Resesrch how that paramete is used in the wild, e.g. by group module, and make up my mind what i think about it). I'm also not sure about the implications for caching (but guess $context goes into the $cid, which is good sec-wise, but floods the cache).
But if not that API, we can do the same with some alter hook. Thinking... What do you think about that?
Comment #4
podarokneeds reroll
Comment #5
shivam_tiwari commentedComment #7
shivam_tiwari commentedComment #8
podarokMR!75 is in
tnx
Comment #10
geek-merlinBulk reopen.
Comment #11
holo96 commentedAs mentioned by my issue when this was merged to 2.x...
Merge request is outdated and is not adding parent to context cosistently, for example
src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php:385 is missing context at all.
Comment #15
holo96 commentedThis patch should workout.
About cache, I think access is only statically cached based off bundle. So it shouldn't flood cache. But, maybe I am wrong?
Comment #16
holo96 commentedComment #17
jonathanshawI've needed this too, for canAddNew().
Comment #18
claudiu.cristeaI would review this but we need a MR.