You are here

services_menu.module in Services Menu 7

Same filename and directory in other branches
  1. 8 services_menu.module
  2. 2.x services_menu.module

File

services_menu.module
View source
<?php

/**
 * Implements hook_permission().
 */
function services_menu_permission() {
  return array(
    "services menu retrieve menu" => array(
      'title' => t('Get menu'),
    ),
  );
}

/**
 * Implements hook_services_resources().
 */
function services_menu_services_resources() {
  return array(
    'menu' => array(
      'retrieve' => array(
        'help' => 'Retrieves a menu',
        'file' => array(
          'type' => 'inc',
          'module' => 'services_menu',
          'name' => 'services_menu.resource',
        ),
        'callback' => '_services_menu_retrieve',
        'access callback' => '_services_menu_access',
        'access arguments' => array(
          'view',
        ),
        'access arguments append' => TRUE,
        'args' => array(
          array(
            'name' => 'menu_name',
            'type' => 'string',
            'description' => 'The name of the menu to get',
            'source' => array(
              'path' => '0',
            ),
            'optional' => FALSE,
          ),
        ),
      ),
    ),
  );
}

/**
 * Access callback for the menu resource.
 *
 * @param $op
 *   The operation that's going to be performed.
 * @param $args
 *   The arguments that will be passed to the callback.
 *
 * @return bool
 *   Whether access is given or not.
 */
function _services_menu_access($op = 'view', $args = array()) {
  global $user;
  $access = FALSE;
  switch ($op) {
    case 'view':
      $access = user_access("services menu retrieve menu");
      if (!in_array($args[0], menu_get_names())) {
        return services_error(t('Menu @menu_name could not be found', array(
          '@menu_name' => $args[0],
        )), 404);
      }
      break;
  }
  return $access;
}

Functions

Namesort descending Description
services_menu_permission Implements hook_permission().
services_menu_services_resources Implements hook_services_resources().
_services_menu_access Access callback for the menu resource.