The Entity API module (D7) has an entity_access() wrapper function:

function entity_access($op, $entity_type, $entity = NULL, $account = NULL) {
  if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) {
    return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type);
  }
}

Once #1696660: Add an entity access API for single entity access is committed we will have a basic entity access API in place. However, that does not add such a wrapper function. I didn't add it in the initial patch because I was not sure if we should do that at all, or, if we want to do it I wasn't entirely sure if it might even make sense to have such a wrapper function on a higher level (for all AccessibleInterface objects alike) for example in common.inc ... So, instead of

entity_access($op, EntityInterface $entity, $user);

we would have:

drupal_access($op, AccessibleInterface $object, $user);

I actually prefer the second solution although I am a bit skeptical regarding its name :).

Comments

sun’s picture

Component: other » entity system
Issue tags: +Entity Access
fubhy’s picture

I wanted to keep it global and not only related to the entity system because of the idea of working with AccessibleInterface instead of EntityInterface in that wrapper.

fago’s picture

Then it should probably be typed_data()->access($data), i.e. part of the typed data manager?

I'd prefer to see a wrapper specific to entities, as I think that would help DX more. E.g.

entity_access($op, EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, $user = NULL);

If we decide to add some general view access support also, we can easily make $entity optional later on as well. If a langcode is passed, it should automatically call $entity->getTranslation($langcode)->access().

fubhy’s picture

Since we also have these issues:

Do we even need to keep this open? I don't see an actual use-case for this wrapper method if we don't require something like that for the menu system anymore.

fubhy’s picture

Status: Active » Closed (duplicate)

Okay, let's fix this here (if we actually want that): #1837360: Add EntityAccess check for routing system