actions_permissions.module 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 $key => $action) {
  9. $permission = actions_permissions_get_perm($action['label'], $key);
  10. $permissions[$permission] = array(
  11. 'title' => t('Execute %label', array('%label' => $action['label'])),
  12. );
  13. }
  14. return $permissions;
  15. }
  16. /**
  17. * Get a list of advanced actions (created through the Action UI).
  18. */
  19. function _actions_permissions_advanced_actions_list() {
  20. $actions = array();
  21. // Actions provided by Drupal that aren't usable in a VBO context.
  22. $hidden_actions = array(
  23. 'system_block_ip_action',
  24. 'system_goto_action',
  25. 'system_message_action',
  26. );
  27. $result = db_query("SELECT * FROM {actions} WHERE parameters > ''");
  28. foreach ($result as $action) {
  29. if (in_array($action->callback, $hidden_actions)) {
  30. continue;
  31. }
  32. $parameters = unserialize($action->parameters);
  33. $actions[$action->aid] = array(
  34. 'label' => $action->label,
  35. 'type' => $action->type,
  36. );
  37. }
  38. return $actions;
  39. }
  40. /**
  41. * Returns the permission name used in user_access().
  42. */
  43. function actions_permissions_get_perm($label, $key) {
  44. return "execute $key";
  45. }