Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add entity_access in core. #863

Closed
klonos opened this issue Apr 11, 2015 · 2 comments
Closed

Add entity_access in core. #863

klonos opened this issue Apr 11, 2015 · 2 comments

Comments

@klonos
Copy link
Member

klonos commented Apr 11, 2015

This was mentioned in backdrop-ops/contrib#71 (comment)

entity_access

I'm not sure how comprehensive this function is. Access checking seems like a good addition to our API as well, but I don't think we have this integrated in core yet. Another good core candidate though.

@btopro
Copy link

btopro commented Oct 7, 2017

very simple addition which would definitely ease migration since entity is a critical piece of most D7 anythings.

/**
 * Determines whether the given user can perform actions on an entity.
 *
 * For create operations, the pattern is to create an entity and then
 * check if the user has create access.
 *
 * @code
 * $node = entity_create('node', array('type' => 'page'));
 * $access = entity_access('create', 'node', $node, $account);
 * @endcode
 *
 * @param $op
 *   The operation being performed. One of 'view', 'update', 'create' or
 *   'delete'.
 * @param $entity_type
 *   The entity type of the entity to check for.
 * @param $entity
 *   Optionally an entity to check access for. If no entity is given, it will be
 *   determined whether access is allowed for all entities of the given type.
 * @param $account
 *   The user to check for. Leave it to NULL to check for the global user.
 *
 * @return boolean
 *   Whether access is allowed or not. If the entity type does not specify any
 *   access information, NULL is returned.
 *
 * @see entity_type_supports()
 */
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);
  }
}

@klonos
Copy link
Member Author

klonos commented Oct 27, 2018

...closing this in favor of #3011

@klonos klonos closed this as completed Oct 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants