actions_permissions.module

Tracking 7.x-3.x branch
  1. drupal
    1. 6 contributions/views_bulk_operations/actions_permissions.module
    2. 7 contributions/views_bulk_operations/actions_permissions.module

Functions & methods

NameDescription
actions_permissions_get_permReturns the permission name used in user_access().
actions_permissions_permissionImplements hook_permission().
_actions_permissions_advanced_actions_listGet a list of advanced actions (created through the Action UI).

File

View source
  1. <?php
  2. /**
  3. * Implements hook_permission().
  4. */
  5. function actions_permissions_permission() {
  6. $permissions = array();
  7. $actions = actions_list() + _actions_permissions_advanced_actions_list();
  8. foreach ($actions as $callback => $action) {
  9. $key = !empty($action['key']) ? $action['key'] : $callback;
  10. $permission = actions_permissions_get_perm($action['label'], $key);
  11. $permissions[$permission] = array(
  12. 'title' => t('Execute %label', array('%label' => $action['label'])),
  13. 'description' => t('Execute action %label (!key).', array('%label' => $action['label'], '!key' => $key)),
  14. );
  15. }
  16. return $permissions;
  17. }
  18. /**
  19. * Get a list of advanced actions (created through the Action UI).
  20. *
  21. * Intentionally not using the "list callback" of the action plugin, so that
  22. * this module doesn't need to depend on Views Bulk Operations.
  23. */
  24. function _actions_permissions_advanced_actions_list() {
  25. $actions = array();
  26. $result = db_query("SELECT * FROM {actions} WHERE parameters > ''");
  27. foreach ($result as $action) {
  28. $parameters = unserialize($action->parameters);
  29. $actions[$action->aid] = array(
  30. 'label' => $action->label,
  31. 'type' => $action->type,
  32. 'key' => $action->callback . (empty($parameters) ? '' : ':'. md5($action->parameters)),
  33. );
  34. }
  35. return $actions;
  36. }
  37. /**
  38. * Returns the permission name used in user_access().
  39. */
  40. function actions_permissions_get_perm($label, $callback) {
  41. return "execute $callback";
  42. }