You are here

function simple_access_node_access_explain in Simple Access 8.3

Same name and namespace in other branches
  1. 5.2 simple_access.module \simple_access_node_access_explain()
  2. 6.2 simple_access.module \simple_access_node_access_explain()
  3. 7.2 simple_access.module \simple_access_node_access_explain()

Implements hook_node_access_explain().

File

./simple_access.module, line 218
Builds simple access definition for content access.

Code

function simple_access_node_access_explain($row) {
  $perms = [
    'view' => t('View'),
    'update' => t('Update'),
    'delete' => t('Delete'),
  ];
  list($type, $id) = explode(':', $row->realm);
  switch ($type) {
    case 'simple_access_group':
      if ($id == 'owner') {
        return t('Access for the content owner');
      }
      if (!($group = SimpleAccessGroup::load($id))) {
        return t('Unknown access restrictions for ":id"', [
          ':id' => $id,
        ]);
      }
      return t('Access restrictions for the ":group" group', [
        ':group' => $group
          ->label(),
      ]);
    case 'simple_access_profile':
      if ($profile = SimpleAccessProfile::load($id)) {
        $message = t('Access restrictions for profile ":profile"', [
          ':profile' => $profile
            ->label(),
        ]);
        if (!empty($profile->access)) {
          foreach ($profile->access as $gid => $access) {
            if ($group = SimpleAccessGroup::load($gid)) {
              $access = array_intersect_key($perms, array_filter($access));
              if (!empty($access)) {
                $message .= ' * ' . t('":group" group can :perm.', [
                  ':group' => $group
                    ->label(),
                  ':perm' => implode(', ', $access),
                ]);
              }
            }
            else {
              $message .= ' * ' . t('Unknown group ":gid"', [
                ':gid' => $gid,
              ]);
            }
          }
        }
      }
      else {
        $message = t('Unknown profile ":id"', [
          ':id' => $id,
        ]);
      }
      return $message;
  }
}