Let's say I have a complex render array that has two variations that depend on a simple if: whether the logged in user can edit a node inside it. There are two scenarios I look for:
- The node was created by the logged in user, or:
- The node's field_group (entity reference) matches the logged in user's field_group.
These two conditions are independent of roles/permissions so I can't fall back on those contexts. Originally, I simply used the "user" context but this would create far too much variation and potentially lead to a very large database table (not to mention it was inefficient to have to cache this again for every user).
I imagine I would need to create a context like: "caneditnode:nid" and somehow pass nid to a handler that would load the Node to check its fields and owner and compare to the data in Drupal::currentUser(). Is that possible? How would I go about doing this? Thanks!