public function TripalEntityUIController::hook_menu

3.x TripalEntityUIController.inc public TripalEntityUIController::hook_menu()

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

File

tripal/includes/TripalEntityUIController.inc, line 11

Class

TripalEntityUIController
UI controller.

Code

public function hook_menu() {
  $items = array();

  // Set this on the object so classes that extend hook_menu() can use it.
  $this->id_count = count(explode('/', $this->path));
  $wildcard = isset($this->entityInfo['admin ui']['menu wildcard']) ? $this->entityInfo['admin ui']['menu wildcard'] : '%entity_object';
  $id_count = count(explode('/', $this->path));

  // The content menu.
  $items[$this->path] = array(
    'title' => 'Tripal Content',
    'page callback' => 'tripal_content_view',
    'file' => 'includes/tripal.admin.inc',
    'file path' => drupal_get_path('module', 'tripal'),
    'access arguments' => array('access tripal content overview'),
    'type' => MENU_LOCAL_TASK,
    'weight' => -9
  );

  $items['bio_data/add'] = array(
    'title' => 'Add Tripal Content',
    'page callback' => 'tripal_add_page',
    'access callback' => '_tripal_entity_add_access',
  );

  // Add a menu item for creating each bundle
  $bundles = array_keys($this->entityInfo['bundles']);
  foreach ($bundles as $bundle_name) {
    $matches = array();
    if (preg_match('/^bio_data_(.*?)$/', $bundle_name, $matches)) {
      $bundle = tripal_load_bundle_entity(array('name' => $bundle_name));
      if (!$bundle) {
        throw new Exception(t("Cannot find bundle that matches: %bundle_name", 
        array('%bundle_name' => $bundle_name)));
      }
      $term_id = $matches[1];
      // Get the term for this bundle
      $term = entity_load('TripalTerm', array('id' => $term_id));
      $term = reset($term);
      $default_description = $term->definition ? $term->definition : '';
      // Set a custom page for adding new tripal data entities.
      $items['bio_data/add/' . $term->id] = array(
        'title' => ucfirst($bundle->label),
        'description' => tripal_get_bundle_variable('description', $bundle->id, $default_description),
        'page callback' => 'drupal_get_form',
        'page arguments' => array('tripal_entity_form', 2),
        'access arguments' => array('create bio_data_' . $term->id),
      );
    }
  }

  // Link for viewing a tripal data type.
  $items['bio_data/' . $wildcard] = array(
    'title callback' => 'tripal_entity_title',
    'title arguments' => array(1),
    'page callback' => 'tripal_view_entity',
    'page arguments' => array(1),
    'access callback' => 'tripal_entity_access',
    'access arguments' => array('view', 1),
    'type' => MENU_CALLBACK,
  );

  // 'View' tab for an individual entity page.
  $items['bio_data/' . $wildcard . '/view'] = array(
    'title' => 'View',
    'page callback' => 'tripal_view_entity',
    'page arguments' => array(1),
    'access callback' => 'tripal_entity_access',
    'access arguments' => array('view', 1),
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => -10,
  );

  // 'Edit' tab for an individual entity page.
  $items['bio_data/' . $wildcard . '/edit'] = array(
    'title' => 'Edit',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('tripal_entity_form', NULL, 1),
    'access callback' => 'tripal_entity_access',
    'access arguments' => array('edit', 1),
    'type' => MENU_LOCAL_TASK,
    'weight' => -8,
  );
  // Menu item for deleting tripal data entities.
  $items['bio_data/' . $wildcard . '/delete'] = array(
    'title' => 'Delete',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('tripal_entity_delete_form', 1),
    'access callback' => 'tripal_entity_access',
    'access arguments' => array('delete', 1),
    'type' => MENU_CALLBACK,
    'weight' => 10,
  );
  return $items;
}