You are here

class ClientsConnectionEntityUIController in Web Service Clients 7.3

UI controller class for connections.

Hierarchy

Expanded class hierarchy of ClientsConnectionEntityUIController

1 string reference to 'ClientsConnectionEntityUIController'
clients_entity_info in ./clients.module
Implements hook_entity_info().

File

includes/clients.ui.inc, line 155
Provides a controller for building an entity overview form.

View source
class ClientsConnectionEntityUIController extends ClientsHandlerEntityUIController {

  /**
   * Provides definitions for implementing hook_menu().
   */
  public function hook_menu() {

    // Tweak what our base class does..
    $items = parent::hook_menu();
    $id_count = count(explode('/', $this->path));
    $wildcard = isset($this->entityInfo['admin ui']['menu wildcard']) ? $this->entityInfo['admin ui']['menu wildcard'] : '%entity_object';

    // Create the base item for the Clients admin tabs...
    $base_item = $items[$this->path];
    $base_item['title'] = t('Clients');
    $base_item['type'] = MENU_NORMAL_ITEM;
    $items['admin/structure/clients'] = $base_item;

    // ... and turn the connections base item into the first tab.
    $items[$this->path]['title'] = t('Connections');
    $items[$this->path]['type'] = MENU_DEFAULT_LOCAL_TASK;

    // Testing system.
    $items[$this->path . '/manage/' . $wildcard . '/test'] = array(
      'title' => 'Test',
      'page callback' => 'drupal_get_form',
      'page arguments' => array(
        'clients_connection_test_form',
        $id_count + 1,
      ),
      'load arguments' => array(
        $this->entityType,
      ),
      'access arguments' => array(
        'administer clients connections',
      ),
      'file' => $this->entityInfo['admin ui']['file'],
      // Need to specify file path as this gets used in entity_menu().
      'file path' => drupal_get_path('module', $this->entityInfo['module']),
      'type' => MENU_LOCAL_TASK,
    );
    if (module_exists('devel')) {

      // Devel tab.
      $items[$this->path . '/manage/' . $wildcard . '/devel'] = array(
        'title' => 'Devel',
        'page callback' => 'clients_connection_page_devel',
        'page arguments' => array(
          $id_count + 1,
        ),
        'load arguments' => array(
          $this->entityType,
        ),
        'access arguments' => array(
          'administer clients connections',
        ),
        'file' => $this->entityInfo['admin ui']['file'],
        // Need to specify file path as this gets used in entity_menu().
        'file path' => drupal_get_path('module', $this->entityInfo['module']),
        'type' => MENU_LOCAL_TASK,
        'weight' => 10,
      );
    }
    return $items;
  }

  /**
   * Retrieves the entities for the admin overview.
   *
   * Overridden to add environment substitution information to the connections.
   */
  function getOverviewEntities($conditions) {
    $connections = parent::getOverviewEntities($conditions);

    // Determine whether any connections will substitute for others.
    $environment_name = variable_get('environment_name', NULL);
    if (isset($environment_name)) {
      foreach ($connections as $name => $connection) {

        // We only need to check substitution in one direction, since we are
        // working over all connections. So we choose the easy one: appending
        // the environment rather than removing it.
        $substitute_name = $name . '_' . $environment_name;
        if (isset($connections[$substitute_name])) {
          $connection->environment_substituted_by = $substitute_name;
          $connections[$substitute_name]->environment_substitute_for = $name;
        }
      }
    }
    return $connections;
  }

  /**
   * Generates the table headers for the overview table.
   */
  protected function overviewTableHeaders($conditions, $rows, $additional_header = array()) {
    $additional_header['substitution'] = t('Substitution');
    $additional_header['endpoint'] = t('Endpoint');
    return parent::overviewTableHeaders($conditions, $rows, $additional_header);
  }

  /**
   * Generates the row for the passed entity and may be overridden in order to
   * customize the rows.
   *
   * @param $additional_cols
   *   Additional columns to be added after the entity label column.
   */
  protected function overviewTableRow($conditions, $id, $entity, $additional_cols = array()) {
    if (isset($entity->environment_substituted_by)) {

      // Machine names don't need sanitizing.
      $substitution = t('Substituted by !connection.', array(
        '!connection' => $entity->environment_substituted_by,
      ));
    }
    elseif (isset($entity->environment_substitute_for)) {
      $substitution = t('Substitute for !connection.', array(
        '!connection' => $entity->environment_substitute_for,
      ));
    }
    else {
      $substitution = '';
    }

    // Add the endpoint to the columns. Our parent class does the handler type.
    $additional_cols['substitution'] = $substitution;
    $additional_cols['endpoint'] = $entity
      ->formatEndpoint($entity->endpoint);
    $row = parent::overviewTableRow($conditions, $id, $entity, $additional_cols);

    // We have to hack these in.
    $additional_ops = array(
      l(t('test'), $this->path . '/manage/' . $id . '/test'),
    );
    array_splice($row, 5, 0, $additional_ops);
    return $row;
  }

  /**
   * Returns the operation count for calculating colspans.
   */
  protected function operationCount() {
    $count = parent::operationCount();

    // Add 1 for our test operation.
    $count++;
    return $count;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ClientsConnectionEntityUIController::getOverviewEntities function Retrieves the entities for the admin overview. Overrides ClientsHandlerEntityUIController::getOverviewEntities
ClientsConnectionEntityUIController::hook_menu public function Provides definitions for implementing hook_menu(). Overrides ClientsHandlerEntityUIController::hook_menu
ClientsConnectionEntityUIController::operationCount protected function Returns the operation count for calculating colspans. Overrides EntityDefaultUIController::operationCount
ClientsConnectionEntityUIController::overviewTableHeaders protected function Generates the table headers for the overview table. Overrides ClientsHandlerEntityUIController::overviewTableHeaders
ClientsConnectionEntityUIController::overviewTableRow protected function Generates the row for the passed entity and may be overridden in order to customize the rows. Overrides ClientsHandlerEntityUIController::overviewTableRow
ClientsHandlerEntityUIController::overviewTable public function Overriden to sort the handlers by machine name. Overrides EntityDefaultUIController::overviewTable
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::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::__construct public function