1.20.x layout.layout.inc layout_layout_access_info()

Implements hook_layout_access_info().

File

modules/layout/includes/layout.layout.inc, line 97
Contains hook implementations Layout module provides for itself.

Code

function layout_layout_access_info() {
  $entity_types = entity_get_info();

  // Provide type-specific plugins for each entity type.
  foreach ($entity_types as $entity_type => $entity_info) {

    // Create a key such as "node_type" or "comment_node_type".
    // Skip users, which don't support multiple types.
    if (!empty($entity_info['entity keys']['bundle'])) {
      $key = $entity_type . '_' . $entity_info['entity keys']['bundle'];
      $bundle_label = array_key_exists('bundle label', $entity_info) ? $entity_info['bundle label'] : 'Type';
      $info[$key] = array(
        'title' => t('@entity: @bundle', array('@entity' => $entity_info['label'], '@bundle' => $bundle_label)),
        'description' => t('Control access by @entity_type @bundle_label.', array('@entity_type' => $entity_type, '@bundle_label' => backdrop_strtolower($bundle_label))),
        'entity_type' => $entity_type,
        'class' => 'EntityBundleLayoutAccess',
        'required contexts' => array(
          $entity_type => $entity_type,
        ),
      );
    }

    // Create a entity id key such as "nid" or "cid".
    $key = $entity_type . '_' . $entity_info['entity keys']['id'];
    $key_label = strtoupper($entity_info['entity keys']['id']);
    $info[$key] = array(
      'title' => t('@entity: @entity_id_key', array('@entity' => $entity_info['label'], '@entity_id_key' => $key_label)),
      'description' => t('Control access by @entity_type @entity_id_key.', array('@entity_type' => $entity_type, '@entity_id_key' => $key_label)),
      'entity_type' => $entity_type,
      'class' => 'EntityIDLayoutAccess',
      'required contexts' => array(
        $entity_type => $entity_type,
      ),
    );
  }

  $info['front'] = array(
    'title' => t('Home page'),
    'description' => t('Is this the home page.'),
    'class' => 'FrontLayoutAccess',
  );
  $info['language'] = array(
    'title' => t('Site language'),
    'description' => t('Control access by the currently active interface language.'),
    'class' => 'LanguageLayoutAccess',
  );
  $info['user_permission'] = array(
    'title' => t('User: Permission'),
    'description' => t('Control access by permission string.'),
    'class' => 'UserPermissionLayoutAccess',
    'required contexts' => array(
      'user' => 'user',
    ),
  );
  $info['user_role'] = array(
    'title' => t('User: Role'),
    'description' => t('Control access by role.'),
    'class' => 'UserRoleLayoutAccess',
    // Contexts are specified as context key => context type. The key will be
    // used in the $contexts array passed to the access class methods. The type
    // references a context provided by hook_layout_context_info().
    'required contexts' => array(
      'user' => 'user',
    ),
    // Optional if needing to clarify between contexts of the same type.
    'required contexts labels' => array(
      'user' => t('User'),
    ),
  );
  $info['path'] = array(
    'title' => t('URL path'),
    'description' => t('Control access by the current path.'),
    'class' => 'PathLayoutAccess',
  );
  return $info;
}