You are here

function trash_flag_permission in Trash Flag 7

Implements hook_permission().

File

./trash_flag.module, line 192

Code

function trash_flag_permission() {
  if ($flag = flag_get_flag('trash')) {
    $trash_action = drupal_strtolower($flag->title);
    $trashed = drupal_strtolower($flag->unflag_denied_text);
    $untrash_action = drupal_strtolower($flag->unflag_short);
  }
  else {
    $trash_action = 'trash';
    $untrash_action = 'untrash';
    $trashed = 'trashed';
  }
  $perms = array();
  $t_args = array(
    '@trash' => $trash_action,
    '@untrash' => $untrash_action,
    '@trashed' => $trashed,
  );
  $perms["trash any content"] = array(
    'title' => t('@trash any content', $t_args),
  );
  $perms["untrash any content"] = array(
    'title' => t('@untrash any content.', $t_args),
    'description' => t('Must be able to view @trashed content to @untrash.', $t_args),
  );
  $perms["view trash content"] = array(
    'title' => t('View @trashed content', $t_args),
    'description' => t('Users with this permission will be able to view @trashed content as normal, unless the @trashed content is specially filtered out.', $t_args),
  );
  $perms["view trash bin"] = array(
    'title' => t('View @trashed listing and content pages', $t_args),
    'description' => t('Users with this permission will be able to view @trashed content in the @trashed listing and visit the content view pages.', $t_args),
  );

  // Generate standard node permissions for all applicable node types.
  foreach (node_type_get_names() as $type => $name) {

    // Build standard list of node permissions for this type.
    $perms["trash any {$type} content"] = array(
      'title' => t('%type_name: @trash any content', $t_args + array(
        '%type_name' => $name,
      )),
    );
    $perms["trash own {$type} content"] = array(
      'title' => t('%type_name: @trash own content', $t_args + array(
        '%type_name' => $name,
      )),
    );
    $perms["untrash any {$type} content"] = array(
      'title' => t('%type_name: @untrash any content', $t_args + array(
        '%type_name' => $name,
      )),
      'description' => t('Must be able to view @trashed content to r@untrash.', $t_args),
    );
    $perms["untrash own {$type} content"] = array(
      'title' => t('%type_name: @untrash own content', $t_args + array(
        '%type_name' => $name,
      )),
      'description' => t('Must be able to view @trashed content to @untrash.', $t_args),
    );
  }
  return $perms;
}