You are here

class PETUIController in Previewable email templates 7

PET UI controller.

Hierarchy

Expanded class hierarchy of PETUIController

1 string reference to 'PETUIController'
pet_entity_info in ./pet.module
Implements hook_entity_info().

File

./pet.module, line 129
Previewable Email Template module.

View source
class PETUIController extends EntityDefaultUIController {

  /**
   * Overrides hook_menu() defaults.
   */
  public function hook_menu() {
    $items = parent::hook_menu();
    $items[$this->path]['description'] = 'Create previewable email templates with token and rules support.';
    return $items;
  }

  /**
   * Defaults a larger pagerLimit for ease of administration.
   *
   * @see EntityDefaultUIController::__construct()
   */
  public function __construct($entity_type, $entity_info) {
    $this->overviewPagerLimit = 100;
    return parent::__construct($entity_type, $entity_info);
  }

  /**
   * Copy of EntityDefaultUIController::overviewTable()  sorts.
   *
   * @see EntityDefaultUIController::overviewTable();
   */
  public function overviewTable($conditions = array()) {
    $query = new EntityFieldQuery();
    $query
      ->entityCondition('entity_type', $this->entityType);

    // PET: Adding table sorts.
    $tableSort = array(
      'name' => array(
        'data' => 'Label',
        'type' => 'property',
        'specifier' => 'name',
      ),
      'status' => array(
        'data' => 'Status',
        'type' => 'property',
        'specifier' => 'status',
      ),
    );
    $query
      ->tableSort($tableSort);

    // Add all conditions to query.
    foreach ($conditions as $key => $value) {
      $query
        ->propertyCondition($key, $value);
    }
    if ($this->overviewPagerLimit) {
      $query
        ->pager($this->overviewPagerLimit);
    }
    $results = $query
      ->execute();
    $ids = isset($results[$this->entityType]) ? array_keys($results[$this->entityType]) : array();
    $entities = $ids ? entity_load($this->entityType, $ids) : array();

    // PET: This removes harcoded sort (only change in this func)

    //ksort($entities);
    $rows = array();
    foreach ($entities as $entity) {
      $rows[] = $this
        ->overviewTableRow($conditions, entity_id($this->entityType, $entity), $entity);
    }
    $render = array(
      '#theme' => 'table',
      '#header' => $this
        ->overviewTableHeaders($conditions, $rows),
      '#rows' => $rows,
      '#empty' => t('None.'),
    );
    return $render;
  }

  /**
   * Generates the table headers for the overview table.
   *
   * Pretty much a clone of EntityDefaultUIController but adds sorts.
   *
   * @see EntityDefaultUIController::overviewTableHeaders()
   */
  protected function overviewTableHeaders($conditions, $rows = array(), $additional_header = array()) {
    $header = $additional_header;

    // Add a different sort.
    array_unshift($header, array(
      'data' => t('Label'),
      'field' => 'name',
      'sort' => 'asc',
    ));
    if (!empty($this->entityInfo['exportable'])) {
      $header[] = array(
        'data' => t('Status'),
        'field' => 'status',
        'sort' => 'desc',
      );
    }

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

}

Members

Namesort descending Modifiers Type Description Overrides
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::overviewTableRow protected function Generates the row for the passed entity and may be overridden in order to customize the rows.
PETUIController::hook_menu public function Overrides hook_menu() defaults. Overrides EntityDefaultUIController::hook_menu
PETUIController::overviewTable public function Copy of EntityDefaultUIController::overviewTable() sorts. Overrides EntityDefaultUIController::overviewTable
PETUIController::overviewTableHeaders protected function Generates the table headers for the overview table. Overrides EntityDefaultUIController::overviewTableHeaders
PETUIController::__construct public function Defaults a larger pagerLimit for ease of administration. Overrides EntityDefaultUIController::__construct