You are here

function services_menu in Services 5

Same name and namespace in other branches
  1. 6.3 services.module \services_menu()
  2. 6 services.module \services_menu()
  3. 6.2 services.module \services_menu()
  4. 7.3 services.module \services_menu()
  5. 7 services.module \services_menu()

Implementation of hook_menu.

File

./services.module, line 41
The module which provides the core code for drupal services

Code

function services_menu($may_cache) {
  $items = array();
  $access = user_access('access services');
  $admin_access = user_access('administer services');
  $path = drupal_get_path('module', 'services');
  if ($may_cache) {

    // admin
    $items[] = array(
      'path' => 'admin/build/services',
      'title' => t('Services'),
      'access' => $admin_access,
      'callback' => 'services_admin_browse_index',
      'description' => t('Allows external applications to communicate with Drupal.'),
    );

    // browse
    $items[] = array(
      'path' => 'admin/build/services/browse',
      'title' => t('Browse'),
      'access' => $admin_access,
      'callback' => 'services_admin_browse_index',
      'description' => t('Browse and test available remote services.'),
      'type' => MENU_DEFAULT_LOCAL_TASK,
    );

    // API Keys
    if (variable_get('services_use_key', TRUE)) {
      $items[] = array(
        'path' => 'admin/build/services/keys',
        'title' => t('Keys'),
        'access' => $admin_access,
        'callback' => 'services_admin_keys_list',
        'description' => t('Manage application access to site services.'),
        'type' => MENU_LOCAL_TASK,
      );
      $items[] = array(
        'path' => 'admin/build/services/keys/list',
        'title' => t('List'),
        'access' => $admin_access,
        'type' => MENU_DEFAULT_LOCAL_TASK,
        'weight' => -10,
      );
      $items[] = array(
        'path' => 'admin/build/services/keys/add',
        'title' => t('Create key'),
        'access' => $admin_access,
        'callback' => 'drupal_get_form',
        'callback arguments' => array(
          'services_admin_keys_form',
        ),
        'type' => MENU_LOCAL_TASK,
      );
    }

    // Settings
    $items[] = array(
      'path' => 'admin/build/services/settings',
      'title' => t('Settings'),
      'access' => $admin_access,
      'callback' => 'drupal_get_form',
      'callback arguments' => 'services_admin_settings',
      'description' => t('Configure service settings.'),
      'type' => MENU_LOCAL_TASK,
    );
    $items[] = array(
      'path' => 'admin/build/services/settings/general',
      'title' => t('General'),
      'access' => $admin_access,
      'callback' => 'drupal_get_form',
      'callback arguments' => 'services_admin_settings',
      'description' => t('Configure service settings.'),
      'type' => MENU_DEFAULT_LOCAL_TASK,
      'weight' => -10,
    );

    // crossdomain.xml
    $items[] = array(
      'path' => 'crossdomain.xml',
      'access' => $access,
      'callback' => 'services_crossdomain_xml',
      'type' => MENU_CALLBACK,
    );
  }
  else {
    if (arg(0) == 'services') {

      // server
      foreach (module_implements('server_info') as $module) {
        $info = module_invoke($module, 'server_info');
        if ($info['#path'] == arg(1)) {
          $items[] = array(
            'path' => 'services/' . $info['#path'],
            'title' => t('Services'),
            'access' => $access,
            'callback' => 'services_server',
            'callback arguments' => array(
              $module,
            ),
            'type' => MENU_CALLBACK,
          );
        }
      }
    }

    // admin
    if (arg(0) == 'admin' && arg(1) == 'build' && arg(2) == 'services') {

      // browse
      if (arg(3) == 'browse' || !arg(3)) {
        require_once "{$path}/services_admin_browse.inc";
        if (arg(4)) {
          $items[] = array(
            'path' => 'admin/build/services/browse/' . arg(4),
            'title' => arg(4),
            'access' => $admin_access,
            'callback' => 'services_admin_browse_method',
            'type' => MENU_LOCAL_TASK,
          );
        }
        drupal_add_css("{$path}/services.css", 'module');
      }

      // keys
      if (arg(3) == 'keys' && variable_get('services_use_key', TRUE)) {
        require_once "{$path}/services_admin_keys.inc";
        if ($key = services_get_key(arg(4))) {
          if (!empty($key)) {
            $items[] = array(
              'path' => 'admin/build/services/keys/' . $key->kid,
              'title' => t('Edit key'),
              'access' => $admin_access,
              'callback' => 'drupal_get_form',
              'callback arguments' => array(
                'services_admin_keys_form',
                $key,
              ),
              'type' => MENU_CALLBACK,
            );
            $items[] = array(
              'path' => 'admin/build/services/keys/' . $key->kid . '/delete',
              'title' => '',
              'access' => $admin_access,
              'callback' => 'drupal_get_form',
              'callback arguments' => array(
                'services_admin_keys_delete_confirm',
                $key,
              ),
              'type' => MENU_CALLBACK,
            );
          }
        }
      }
    }
  }
  return $items;
}