You are here

public function RoomsUnitUIController::hook_menu in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7

Overrides hook_menu() defaults. Main reason for doing this is that parent class hook_menu() is optimized for entity type administration.

Overrides EntityDefaultUIController::hook_menu

File

modules/rooms_unit/rooms_unit.admin.inc, line 21
Rooms editing UI.

Class

RoomsUnitUIController
UI controller.

Code

public function hook_menu() {
  $items = array();
  $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] = array(
    'title' => 'Bookable Units',
    'description' => 'Add, edit, and update bookable units.',
    'page callback' => 'system_admin_menu_block_page',
    'access arguments' => array(
      'access bookable units overview',
    ),
    'file path' => drupal_get_path('module', 'system'),
    'file' => 'system.admin.inc',
    'weight' => 10,
  );

  // Change the add page menu to multiple types of entities.
  $items[$this->path . '/add'] = array(
    'title' => 'Add a Bookable Unit',
    'description' => 'Create a new bookable unit.',
    'page callback' => 'rooms_unit_add_page',
    'access callback' => '_rooms_unit_add_access',
    'type' => MENU_NORMAL_ITEM,
    'weight' => 20,
    'file' => 'rooms_unit.admin.inc',
    'file path' => drupal_get_path('module', $this->entityInfo['module']),
  );

  // Add menu items to add each different type of room.
  foreach (rooms_unit_get_types() as $type) {
    $items[$this->path . '/add/' . $type->type] = array(
      'title' => 'Add @unit_type_label unit',
      'title arguments' => array(
        '@unit_type_label' => $type->label,
      ),
      'page callback' => 'rooms_unit_create_form_wrapper',
      'page arguments' => array(
        $type->type,
      ),
      'access callback' => 'rooms_unit_access',
      'access arguments' => array(
        'create',
        rooms_unit_create(array(
          'type' => $type->type,
          'uid' => 0,
        )),
      ),
      'file' => 'rooms_unit.admin.inc',
      'file path' => drupal_get_path('module', $this->entityInfo['module']),
    );
  }

  // Loading and editing Rooms entities.
  $items[$this->path . '/unit/' . $wildcard] = array(
    'title callback' => 'rooms_unit_page_title',
    'title arguments' => array(
      $id_count + 1,
    ),
    'page callback' => 'rooms_unit_page_view',
    'page arguments' => array(
      $id_count + 1,
    ),
    'access callback' => 'rooms_unit_access',
    'access arguments' => array(
      'view',
      $id_count + 1,
    ),
    'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
  );
  $items[$this->path . '/unit/' . $wildcard . '/view'] = array(
    'title' => 'View',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => -10,
    'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
  );
  $items[$this->path . '/unit/' . $wildcard . '/edit'] = array(
    'title' => 'Edit',
    'page callback' => 'rooms_unit_form_wrapper',
    'page arguments' => array(
      $id_count + 1,
    ),
    'access callback' => 'rooms_unit_access',
    'access arguments' => array(
      'update',
      $id_count + 1,
    ),
    'weight' => 0,
    'type' => MENU_LOCAL_TASK,
    'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
    'file' => 'rooms_unit.admin.inc',
    'file path' => drupal_get_path('module', $this->entityInfo['module']),
  );
  $items[$this->path . '/unit/' . $wildcard . '/delete'] = array(
    'title' => 'Delete',
    'page callback' => 'rooms_unit_delete_form_wrapper',
    'page arguments' => array(
      $id_count + 1,
    ),
    'access callback' => 'rooms_unit_access',
    'access arguments' => array(
      'delete',
      $id_count + 1,
    ),
    'type' => MENU_LOCAL_TASK,
    'context' => MENU_CONTEXT_INLINE,
    'weight' => 10,
    'file' => 'rooms_unit.admin.inc',
    'file path' => drupal_get_path('module', $this->entityInfo['module']),
  );

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