You are here

class BatBookingUIController in Booking and Availability Management Tools for Drupal 7

UI controller.

Hierarchy

Expanded class hierarchy of BatBookingUIController

1 string reference to 'BatBookingUIController'
bat_booking_entity_info in modules/bat_booking/bat_booking.module
Implements hook_entity_info().

File

modules/bat_booking/bat_booking.admin.inc, line 11
BatBooking editing UI.

View source
class BatBookingUIController extends EntityDefaultUIController {

  /**
   * Overrides hook_menu() defaults.
   */
  public function hook_menu() {
    $items = parent::hook_menu();

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

    // Add menu items to add each different type of bookings.
    foreach (bat_booking_get_types() as $booking_type) {
      $items[$this->path . '/add/' . $booking_type->type] = array(
        'title' => 'Add @booking_type_label booking',
        'title arguments' => array(
          '@booking_type_label' => $booking_type->label,
        ),
        'page callback' => 'bat_booking_create_form_wrapper',
        'page arguments' => array(
          $booking_type->type,
        ),
        'access callback' => 'bat_booking_access',
        'access arguments' => array(
          'create',
          bat_booking_create(array(
            'type' => $booking_type->type,
            'uid' => 0,
          )),
        ),
        'file' => 'bat_booking.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,
      ),
    );
    $booking_type = bat_booking_type_load($entity->type);
    $row[] = $booking_type->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);
      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 Booking Entities page within the class
   * so it can easily be extended/overridden.
   */
  public function addPage() {
    $item = menu_get_item();
    $booking_types = bat_booking_get_types();
    if (count($booking_types) == 1) {
      $booking_type = reset($booking_types);
      drupal_goto($this->path . '/add/' . $booking_type->type);
    }
    $items = array();
    foreach ($booking_types as $booking_type) {
      $items[] = array(
        'title' => t('Add @booking_type_label booking', array(
          '@booking_type_label' => $booking_type->label,
        )),
        'href' => $this->path . '/add/' . $booking_type->type,
        'description' => '',
      );
    }
    return array(
      '#theme' => 'bat_booking_add_list',
      '#content' => $items,
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BatBookingUIController::addPage public function Creates the markup for the add Booking Entities page within the class so it can easily be extended/overridden.
BatBookingUIController::hook_menu public function Overrides hook_menu() defaults. Overrides EntityDefaultUIController::hook_menu
BatBookingUIController::overviewTableHeaders protected function Overrides overviewTableHeaders() defaults. Overrides EntityDefaultUIController::overviewTableHeaders
BatBookingUIController::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