You are here

function workbench_access_requirements in Workbench Access 7

Implements hook_requirements() to check if workbench_access is configured.

Parameters

$phase:

File

./workbench_access.install, line 159
Install file for Workbench Access.

Code

function workbench_access_requirements($phase) {
  $requirements = array();
  if ($phase == 'runtime') {
    $tree = workbench_access_get_active_tree();
    $roles = workbench_access_get_roles('access workbench access by role');
    $types = workbench_access_check_access_fields();
    $description = array();
    workbench_access_load_include();
    $modules = module_implements('workbench_access_info');
    if (empty($modules) && !module_exists('taxonomy') && !module_exists('menu')) {
      $description[] = t('No modules are enabled that support access hierarchies. Menu and Taxonomy are two options.');
    }

    // If this variable has not been set, workbench access is not fully configured.
    if (!variable_get('workbench_access', FALSE)) {
      $description[] = workbench_access_configuration_needed_message();
    }

    // If no sections, then nothing works.
    if (empty($tree['active'])) {
      $description[] = workbench_access_sections_needed_message();
    }
    if (empty($roles)) {
      $description[] = t('At least one role must be have the <a href="!url">Allow all members of this role to be assigned to Workbench Access sections</a> permission', array(
        '!url' => url('admin/people/permissions', array(
          'fragment' => 'module-workbench_access',
        )),
      ));
    }
    if (!empty($types)) {
      $items = array();
      foreach ($types as $type) {
        $items[] = check_plain(node_type_get_name($type));
      }
      $description[] = t('The following content types are not properly configured for access control: !types', array(
        '!types' => theme('item_list', array(
          'items' => $items,
        )),
      ));
    }
    if (empty($description)) {
      $requirements['workbench_access'] = array(
        'title' => t('Workbench Access'),
        'value' => t('Configured'),
        'severity' => REQUIREMENT_OK,
        'description' => t('Workbench Access is configured properly, using %scheme as the access scheme.', array(
          '%scheme' => variable_get('workbench_access'),
        )),
      );
    }
    else {
      $requirements['workbench_access'] = array(
        'title' => t('Workbench Access'),
        'value' => t('Not configured'),
        'severity' => REQUIREMENT_ERROR,
        'description' => theme('item_list', array(
          'items' => $description,
        )),
      );
    }
  }
  return $requirements;
}