You are here

class BatTypeUIController in Booking and Availability Management Tools for Drupal 7

UI controller.

Hierarchy

Expanded class hierarchy of BatTypeUIController

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

File

modules/bat_unit/bat_type.admin.inc, line 15
BatType editing UI.

View source
class BatTypeUIController extends EntityDefaultUIController {

  /**
   * Overrides hook_menu() defaults.
   */
  public function hook_menu() {
    $items = parent::hook_menu();
    $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 Types.';
    $items[$this->path]['weight'] = 10;

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

    // Add menu items to add each different bundle of Bat Types.
    foreach (bat_unit_get_type_bundles() as $bundle) {
      $items[$this->path . '/add/' . $bundle->type] = array(
        'title' => 'Add @type_bundle_label type',
        'title arguments' => array(
          '@type_bundle_label' => $bundle->label,
        ),
        'page callback' => 'bat_type_create_form_wrapper',
        'page arguments' => array(
          $bundle->type,
        ),
        'access callback' => 'bat_type_access',
        'access arguments' => array(
          'create',
          bat_type_create(array(
            'type' => $bundle->type,
            'uid' => 0,
          )),
        ),
        'file' => 'bat_type.admin.inc',
        'file path' => drupal_get_path('module', $this->entityInfo['module']),
      );
    }

    // Loading and editing type entities.
    $items[$this->path . '/manage/' . $wildcard] = array(
      'title callback' => 'bat_type_page_title',
      'title arguments' => array(
        $id_count + 1,
      ),
      'page callback' => 'bat_type_page_view',
      'page arguments' => array(
        $id_count + 1,
      ),
      'access callback' => 'bat_type_access',
      'access arguments' => array(
        'view',
        $id_count + 1,
      ),
      'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
    );
    $items[$this->path . '/manage/' . $wildcard . '/view'] = array(
      'title callback' => 'bat_type_title_callback',
      'title arguments' => array(
        $id_count + 1,
        'view',
      ),
      'type' => MENU_DEFAULT_LOCAL_TASK,
      'weight' => -10,
      'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
    );
    if (module_exists('diff')) {
      $items[$this->path . '/manage/' . $wildcard . '/revisions/view'] = array(
        'title' => '',
        'page callback' => 'bat_type_compare_revisions',
        'page arguments' => array(
          $id_count + 1,
          $id_count + 4,
          $id_count + 5,
        ),
        'access callback' => TRUE,
        'type' => MENU_LOCAL_TASK,
        'file' => 'bat_type.diff.inc',
        'file path' => drupal_get_path('module', $this->entityInfo['module']),
      );
    }
    $items[$this->path . '/manage/' . $wildcard . '/revision/%/view'] = array(
      'title' => 'View Revision',
      'page callback' => 'bat_type_revision_view',
      'page arguments' => array(
        $id_count + 1,
        $id_count + 3,
      ),
      'access callback' => 'bat_type_access_revision',
      'access arguments' => array(
        'view',
        $id_count + 1,
        $id_count + 3,
      ),
      'file' => 'bat_type.admin.inc',
      'file path' => drupal_get_path('module', $this->entityInfo['module']),
    );
    $items[$this->path . '/manage/' . $wildcard . '/revision/%/revert'] = array(
      'page callback' => 'drupal_get_form',
      'page arguments' => array(
        'bat_type_revision_revert_confirm',
        $id_count + 1,
        $id_count + 3,
      ),
      'access callback' => 'bat_type_access_revision',
      'access arguments' => array(
        'revert',
        $id_count + 1,
        $id_count + 3,
      ),
      'file' => 'bat_type.admin.inc',
      'file path' => drupal_get_path('module', $this->entityInfo['module']),
    );
    $items[$this->path . '/manage/' . $wildcard . '/revision/%/delete'] = array(
      'page callback' => 'drupal_get_form',
      'page arguments' => array(
        'bat_type_revision_delete_confirm',
        $id_count + 1,
        $id_count + 3,
      ),
      'access callback' => 'bat_type_access_revision',
      'access arguments' => array(
        'delete',
        $id_count + 1,
        $id_count + 3,
      ),
      'file' => 'bat_type.admin.inc',
      'file path' => drupal_get_path('module', $this->entityInfo['module']),
    );
    $items[$this->path . '/manage/' . $wildcard . '/edit'] = array(
      'title callback' => 'bat_type_title_callback',
      'title arguments' => array(
        $id_count + 1,
        'edit',
      ),
      'page callback' => 'bat_type_form_wrapper',
      'page arguments' => array(
        $id_count + 1,
      ),
      'access callback' => 'bat_type_access',
      'access arguments' => array(
        'update',
        $id_count + 1,
      ),
      'weight' => 0,
      'type' => MENU_LOCAL_TASK,
      'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
      'file' => 'bat_type.admin.inc',
      'file path' => drupal_get_path('module', $this->entityInfo['module']),
    );
    $items[$this->path . '/manage/' . $wildcard . '/delete'] = array(
      'title' => 'Delete',
      'page callback' => 'bat_type_delete_form_wrapper',
      'page arguments' => array(
        $id_count + 1,
      ),
      'access callback' => 'bat_type_access',
      'access arguments' => array(
        'delete',
        $id_count + 1,
      ),
      'type' => MENU_LOCAL_TASK,
      'context' => MENU_CONTEXT_INLINE,
      'weight' => 10,
      'file' => 'bat_type.admin.inc',
      'file path' => drupal_get_path('module', $this->entityInfo['module']),
    );

    // Menu item for viewing types.
    $items['type/' . $wildcard] = array(
      'title callback' => 'bat_type_page_title',
      'title arguments' => array(
        1,
      ),
      'page callback' => 'bat_type_page_view',
      'page arguments' => array(
        1,
      ),
      'access callback' => 'bat_type_access',
      'access arguments' => array(
        'view',
        1,
      ),
      'type' => MENU_CALLBACK,
    );
    $items[$this->path . '/manage/' . $wildcard . '/units/add'] = array(
      'title' => 'Add Units',
      'page callback' => 'bat_type_add_units_page',
      'page arguments' => array(
        5,
      ),
      'access arguments' => array(
        'create bat_unit entities',
      ),
      'file' => 'bat_type.admin.inc',
      'file path' => drupal_get_path('module', $this->entityInfo['module']),
      'type' => MENU_CALLBACK,
    );
    foreach (bat_unit_get_bundles() as $bundle) {
      $items[$this->path . '/manage/' . $wildcard . '/units/add/' . $bundle->type] = array(
        'title' => 'Add @unit_bundle_label unit',
        'title arguments' => array(
          '@unit_bundle_label' => $bundle->label,
        ),
        'page callback' => 'bat_type_add_units_form_wrapper',
        'page arguments' => array(
          5,
          8,
        ),
        'access callback' => 'bat_unit_access',
        'access arguments' => array(
          'create',
          bat_unit_create(array(
            'type' => $bundle->type,
            'uid' => 0,
          )),
        ),
        'file' => 'bat_type.admin.inc',
        'file path' => drupal_get_path('module', $this->entityInfo['module']),
      );
    }
    return $items;
  }

  /**
   * Overrides overviewTableHeaders() defaults.
   */
  protected function overviewTableHeaders($conditions, $rows, $additional_header = array()) {
    $header = array(
      t('ID'),
      t('Name'),
      t('Bundle'),
    );
    if (!empty($this->entityInfo['exportable'])) {
      $header[] = t('Status');
    }

    // Add operations with the right colspan.
    $header[] = array(
      'data' => t('Operations'),
      'colspan' => $this
        ->operationCount(),
    );
    return $header;
  }

  /**
   * Overrides overviewTableRow() defaults.
   */
  protected function overviewTableRow($conditions, $id, $entity, $additional_cols = array()) {
    $entity_uri = entity_uri($this->entityType, $entity);
    $row[] = $id;
    $row[] = array(
      'data' => array(
        '#theme' => 'entity_ui_overview_item',
        '#label' => entity_label($this->entityType, $entity),
        '#name' => !empty($this->entityInfo['exportable']) ? entity_id($this->entityType, $entity) : FALSE,
        '#url' => $entity_uri ? $entity_uri : FALSE,
        '#entity_type' => $this->entityType,
      ),
    );
    $type_bundle = bat_type_bundle_load($entity->type);
    $row[] = $type_bundle->label;

    // Add a row for the exportable status.
    if (!empty($this->entityInfo['exportable'])) {
      $row[] = array(
        'data' => array(
          '#theme' => 'entity_status',
          '#status' => $entity->{$this->statusKey},
        ),
      );
    }

    // In case this is a bundle, we add links to the field ui tabs.
    $field_ui = !empty($this->entityInfo['bundle of']) && entity_type_is_fieldable($this->entityInfo['bundle of']) && module_exists('field_ui');

    // For exportable entities we add an export link.
    $exportable = !empty($this->entityInfo['exportable']);

    // If i18n integration is enabled, add a link to the translate tab.
    $i18n = !empty($this->entityInfo['i18n controller class']);

    // Add operations depending on the status.
    if (entity_has_status($this->entityType, $entity, ENTITY_FIXED)) {
      $row[] = array(
        'data' => l(t('clone'), $this->path . '/manage/' . $id . '/clone'),
        'colspan' => $this
          ->operationCount(),
      );
    }
    else {
      $row[] = l(t('edit'), $this->path . '/manage/' . $id . '/edit');
      if ($field_ui) {
        $row[] = l(t('manage fields'), $this->path . '/manage/' . $id . '/fields');
        $row[] = l(t('manage display'), $this->path . '/manage/' . $id . '/display');
      }
      if ($i18n) {
        $row[] = l(t('translate'), $this->path . '/manage/' . $id . '/translate');
      }
      if ($exportable) {
        $row[] = l(t('clone'), $this->path . '/manage/' . $id . '/clone');
      }
      if (empty($this->entityInfo['exportable']) || !entity_has_status($this->entityType, $entity, ENTITY_IN_CODE)) {
        $row[] = l(t('delete'), $this->path . '/manage/' . $id . '/delete', array(
          'query' => drupal_get_destination(),
        ));
      }
      elseif (entity_has_status($this->entityType, $entity, ENTITY_OVERRIDDEN)) {
        $row[] = l(t('revert'), $this->path . '/manage/' . $id . '/revert', array(
          'query' => drupal_get_destination(),
        ));
      }
      else {
        $row[] = '';
      }
    }
    if ($exportable) {
      $row[] = l(t('export'), $this->path . '/manage/' . $id . '/export');
    }
    return $row;
  }

  /**
   * Creates the markup for the add Bat Type Entities page within the class
   * so it can easily be extended/overridden.
   */
  public function addPage() {
    $item = menu_get_item();
    $bundles = bat_unit_get_type_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 @type_bundle_label type', array(
          '@type_bundle_label' => $bundle->label,
        )),
        'href' => $this->path . '/add/' . $bundle->type,
        'description' => '',
      );
    }
    return array(
      '#theme' => 'bat_type_add_list',
      '#content' => $items,
    );
  }

  /**
   * Creates the markup for the add Bat Units pages when units are added through
   * the Type configuration page.
   */
  public function addUnitsPage() {
    $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) {
      drupal_goto($item['href'] . '/' . array_shift($bundles)->type);
    }
    $content['bundles'] = $bundles;
    $content['item'] = $item;
    return array(
      '#theme' => 'bat_type_unit_add_list',
      '#content' => $content,
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BatTypeUIController::addPage public function Creates the markup for the add Bat Type Entities page within the class so it can easily be extended/overridden.
BatTypeUIController::addUnitsPage public function Creates the markup for the add Bat Units pages when units are added through the Type configuration page.
BatTypeUIController::hook_menu public function Overrides hook_menu() defaults. Overrides EntityDefaultUIController::hook_menu
BatTypeUIController::overviewTableHeaders protected function Overrides overviewTableHeaders() defaults. Overrides EntityDefaultUIController::overviewTableHeaders
BatTypeUIController::overviewTableRow protected function Overrides overviewTableRow() defaults. Overrides EntityDefaultUIController::overviewTableRow
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::__construct public function