Backdrop 1.13.0 added new consistency to access checking for different types of entities, including nodes, taxonomy terms, user accounts, and comments. Access can now be checked for all of these different types using two different approaches:
// Using a general function that works on all entity types:
entity_access($entity_type, $entity, $op, $account);
// Checking the entity using a method:
$entity->access($op, $account);
The $op parameter may be one of 'create', 'view', 'update', or 'delete' on any entity type.
Prior to Backdrop 1.13.0, the $op parameter for Taxonomy Terms and Comments used "edit" instead of "update". The operations were renamed to match those of other entities like users and nodes.
Before Backdrop 1.13.0:
// Checking update access on a term:
$update_access = taxonomy_term_access('edit', $term);
// Checking update access on a comment:
$update_access = comment_access('edit', $comment)
After Backdrop 1.13.0:
// Checking update access on a term:
$update_access = taxonomy_term_access('update', $term);
// Checking update access on a comment:
$update_access = comment_access('update', $comment)
Alternatively, access can also be checked by using the new generic entity_access()
function or the Entity::access()
method:
// Checking access using the new Entity::access() method:
$update_access = $comment->access('update');
// Or using the generic entity_access() function:
entity_access('update', 'comment', $comment);
The old "edit" $op value may still be used in both taxonomy_term_access()
and comment_access()
, but a deprecated notice will be logged if enabled in watchdog.