You are here

class BatUnitUIController in Booking and Availability Management Tools for Drupal 7

UI controller.

Hierarchy

Expanded class hierarchy of BatUnitUIController

1 string reference to 'BatUnitUIController'
bat_unit_entity_info in modules/bat_unit/bat_unit.module
Implements hook_entity_info().

File

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

View source
class BatUnitUIController extends EntityDefaultUIController {

  /**
   * Overrides hook_menu() defaults.
   */
  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;
  }

  /**
   * Creates the markup for the add Unit Entities page within the class
   * so it can easily be extended/overridden.
   */
  public function addPage() {
    $item = menu_get_item();
    $bundles = bat_unit_get_bundles();

    // If there is only one unit bundle go straight to that page.
    if (count($bundles) == 1) {
      $bundle = reset($bundles);
      drupal_goto($this->path . '/add/' . $bundle->type);
    }
    $items = array();
    foreach ($bundles as $bundle) {
      $items[] = array(
        'title' => t('Add @unit_bundle_label unit', array(
          '@unit_bundle_label' => $bundle->label,
        )),
        'href' => $this->path . '/add/' . $bundle->type,
        'description' => '',
      );
    }
    return array(
      '#theme' => 'bat_unit_add_list',
      '#content' => $items,
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BatUnitUIController::addPage public function Creates the markup for the add Unit Entities page within the class so it can easily be extended/overridden.
BatUnitUIController::hook_menu public function Overrides hook_menu() defaults. Overrides EntityDefaultUIController::hook_menu
EntityDefaultUIController::$entityInfo protected property
EntityDefaultUIController::$entityType protected property
EntityDefaultUIController::$id_count protected property
EntityDefaultUIController::$overviewPagerLimit public property Defines the number of entries to show per page in overview table.
EntityDefaultUIController::applyOperation public function Applies an operation to the given entity.
EntityDefaultUIController::entityFormSubmitBuildEntity public function Entity submit builder invoked via entity_ui_form_submit_build_entity().
EntityDefaultUIController::hook_forms public function Provides definitions for implementing hook_forms().
EntityDefaultUIController::operationCount protected function Returns the operation count for calculating colspans.
EntityDefaultUIController::operationForm public function Builds the operation form.
EntityDefaultUIController::operationFormSubmit public function Operation form submit callback. 1
EntityDefaultUIController::operationFormValidate public function Operation form validation callback.
EntityDefaultUIController::overviewForm public function Builds the entity overview form.
EntityDefaultUIController::overviewFormSubmit public function Overview form submit callback.
EntityDefaultUIController::overviewFormValidate public function Overview form validation callback.
EntityDefaultUIController::overviewTable public function Generates the render array for a overview table for arbitrary entities matching the given conditions.
EntityDefaultUIController::overviewTableHeaders protected function Generates the table headers for the overview table.
EntityDefaultUIController::overviewTableRow protected function Generates the row for the passed entity and may be overridden in order to customize the rows.
EntityDefaultUIController::__construct public function