You are here

public function BatUnitUIController::hook_menu in Booking and Availability Management Tools for Drupal 7

Overrides hook_menu() defaults.

Overrides EntityDefaultUIController::hook_menu

File

modules/bat_unit/bat_unit.admin.inc, line 20
BatUnit editing UI.

Class

BatUnitUIController
UI controller.

Code

public function hook_menu() {
  $items = parent::hook_menu();
  $items['admin/bat/config/units']['access callback'] = FALSE;
  $id_count = count(explode('/', $this->path));
  $wildcard = isset($this->entityInfo['admin ui']['menu wildcard']) ? $this->entityInfo['admin ui']['menu wildcard'] : '%' . $this->entityType;
  $items[$this->path]['description'] = 'Add, edit, and update units.';
  $items[$this->path]['weight'] = 10;

  // Change the add page menu to multiple types of entities.
  $items[$this->path . '/add']['title'] = 'Add a Unit';
  $items[$this->path . '/add']['description'] = 'Create a new unit.';
  $items[$this->path . '/add']['page callback'] = 'bat_unit_add_page';
  $items[$this->path . '/add']['access callback'] = 'bat_unit_add_access';
  unset($items[$this->path . '/add']['title callback']);

  // Add menu items to add each different type of units.
  foreach (bat_unit_get_bundles() as $bundle) {
    $items[$this->path . '/add/' . $bundle->type] = array(
      'title' => 'Add @unit_bundle_label unit',
      'title arguments' => array(
        '@unit_bundle_label' => $bundle->label,
      ),
      'page callback' => 'bat_unit_create_form_wrapper',
      'page arguments' => array(
        $bundle->type,
      ),
      'access callback' => 'bat_unit_access',
      'access arguments' => array(
        'create',
        bat_unit_create(array(
          'type' => $bundle->type,
          'uid' => 0,
        )),
      ),
      'file' => 'bat_unit.admin.inc',
      'file path' => drupal_get_path('module', $this->entityInfo['module']),
    );
  }

  // Loading and editing Unit entities.
  $items[$this->path . '/unit/' . $wildcard] = array(
    'title callback' => 'bat_unit_page_title',
    'title arguments' => array(
      $id_count + 1,
    ),
    'page callback' => 'bat_unit_page_view',
    'page arguments' => array(
      $id_count + 1,
    ),
    'access callback' => 'bat_unit_access',
    'access arguments' => array(
      'view',
      $id_count + 1,
    ),
    'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
  );
  $items[$this->path . '/unit/' . $wildcard . '/edit'] = array(
    'title' => 'Edit',
    'page callback' => 'bat_unit_form_wrapper',
    'page arguments' => array(
      $id_count + 1,
    ),
    'access callback' => 'bat_unit_access',
    'access arguments' => array(
      'update',
      $id_count + 1,
    ),
    'weight' => 0,
    'type' => MENU_LOCAL_TASK,
    'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
    'file' => 'bat_unit.admin.inc',
    'file path' => drupal_get_path('module', $this->entityInfo['module']),
  );
  $items[$this->path . '/unit/' . $wildcard . '/delete'] = array(
    'title' => 'Delete',
    'page callback' => 'bat_unit_delete_form_wrapper',
    'page arguments' => array(
      $id_count + 1,
    ),
    'access callback' => 'bat_unit_access',
    'access arguments' => array(
      'delete',
      $id_count + 1,
    ),
    'type' => MENU_LOCAL_TASK,
    'context' => MENU_CONTEXT_INLINE,
    'weight' => 10,
    'file' => 'bat_unit.admin.inc',
    'file path' => drupal_get_path('module', $this->entityInfo['module']),
  );

  // Menu item for viewing unit.
  $items['unit/' . $wildcard] = array(
    'title callback' => 'bat_unit_page_title',
    'title arguments' => array(
      1,
    ),
    'page callback' => 'bat_unit_page_view',
    'page arguments' => array(
      1,
    ),
    'access callback' => 'bat_unit_access',
    'access arguments' => array(
      'view',
      1,
    ),
    'type' => MENU_CALLBACK,
  );
  return $items;
}