You are here

class OAuth2ServerScopeUIController in OAuth2 Server 7

UI controller.

Hierarchy

Expanded class hierarchy of OAuth2ServerScopeUIController

1 string reference to 'OAuth2ServerScopeUIController'
oauth2_server_entity_info in ./oauth2_server.module
Implements hook_entity_info().

File

includes/oauth2_server.scope_admin.inc, line 10
Admin UI for scopes.

View source
class OAuth2ServerScopeUIController extends EntityDefaultUIController {
  public function __construct($entity_type, $entity_info) {
    $this->statusKey = 'status';
    $this->entityType = $entity_type;
    $this->entityInfo = $entity_info;

    // Stop the UI from mentioning "OAuth2 scope" everywhere.
    $this->entityInfo['label'] = 'Scope';

    // Replace the server placeholder with the server name, since the path
    // is used for links and redirects.
    $this->path = str_replace('%oauth2_server', arg(4), $this->entityInfo['admin ui']['path']);
  }

  /**
   * Overrides EntityDefaultUIController::hook_menu().
   */
  public function hook_menu() {
    $items = array();
    $path = 'admin/structure/oauth2-servers/manage/%/scopes';
    $id_pos = count(explode('/', $path));
    $items[$path] = array(
      'title' => 'Scopes',
      'page callback' => 'drupal_get_form',
      'page arguments' => array(
        'oauth2_server_scope_overview_form',
        'oauth2_server_scope',
      ),
      'description' => 'Manage scopes.',
      'access callback' => 'entity_access',
      'access arguments' => array(
        'view',
        'oauth2_server_scope',
      ),
      'type' => MENU_LOCAL_TASK,
      'file' => 'includes/entity.ui.inc',
      'weight' => 9,
    );
    $items[$path . '/add'] = array(
      'title' => 'Add scope',
      'page callback' => 'entity_ui_get_bundle_add_form',
      'page arguments' => array(
        'oauth2_server_scope',
        4,
      ),
      'access callback' => 'entity_access',
      'access arguments' => array(
        'create',
        'oauth2_server_scope',
      ),
      'type' => MENU_LOCAL_ACTION,
      'file' => $this->entityInfo['admin ui']['file'],
      'file path' => drupal_get_path('module', 'oauth2_server'),
    );

    // The regular Entity API way would be to use
    // $path . '/manage/%entity_object' here, but Drupal's Menu API is limited
    // to 9 levels, one too little for that to work.
    $items[$path . '/%entity_object'] = array(
      'title' => 'Edit',
      'title callback' => 'entity_label',
      'title arguments' => array(
        'oauth2_server_scope',
        $id_pos,
      ),
      'page callback' => 'entity_ui_get_form',
      'page arguments' => array(
        'oauth2_server_scope',
        $id_pos,
      ),
      'load arguments' => array(
        'oauth2_server_scope',
      ),
      'access callback' => 'entity_access',
      'access arguments' => array(
        'update',
        'oauth2_server_scope',
        $id_pos,
      ),
      'file' => $this->entityInfo['admin ui']['file'],
      'file path' => drupal_get_path('module', 'oauth2_server'),
    );
    $items[$path . '/%entity_object/edit'] = array(
      'title' => 'Edit',
      'load arguments' => array(
        'oauth2_server_scope',
      ),
      'type' => MENU_DEFAULT_LOCAL_TASK,
    );
    $items[$path . '/%entity_object/delete'] = array(
      'page callback' => 'drupal_get_form',
      'page arguments' => array(
        'oauth2_server_scope_operation_form',
        'oauth2_server_scope',
        $id_pos,
        'delete',
      ),
      'load arguments' => array(
        'oauth2_server_scope',
      ),
      'access callback' => 'entity_access',
      'access arguments' => array(
        'delete',
        'oauth2_server_scope',
        $id_pos,
      ),
      'file' => 'includes/entity.ui.inc',
    );
    return $items;
  }

  /**
   * Overrides EntityDefaultUIController::overviewTable().
   */
  public function overviewTable($conditions = array()) {
    $this->server = oauth2_server_load(arg(4));
    $conditions['server'] = arg(4);
    return parent::overviewTable($conditions);
  }

  /**
   * Overrides EntityDefaultUIController::overviewTableHeaders().
   */
  protected function overviewTableHeaders($conditions, $rows, $additional_header = array()) {
    $header = $additional_header;
    array_unshift($header, t('Scope'));

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

  /**
   * Overrides EntityDefaultUIController::overviewTableRow().
   */
  protected function overviewTableRow($conditions, $id, $entity, $additional_cols = array()) {
    $entity_uri = entity_uri($this->entityType, $entity);
    $entity_label = entity_label($this->entityType, $entity);
    if ($this->server && $this->server->settings['default_scope'] == $entity->name) {
      $entity_label .= ' (' . t('Default') . ')';
    }
    $row[] = array(
      'data' => array(
        '#theme' => 'entity_ui_overview_item',
        '#label' => $entity_label,
        '#name' => FALSE,
        '#url' => $entity_uri ? $entity_uri : FALSE,
        '#entity_type' => $this->entityType,
      ),
    );

    // Add in any passed additional cols.
    foreach ($additional_cols as $col) {
      $row[] = $col;
    }

    // Add the edit and delete links.
    $row[] = l(t('edit'), $this->path . '/' . $id);
    if (module_exists('i18n_string')) {
      $row[] = l(t('translate'), $this->path . '/' . $id . '/translate');
    }
    $row[] = l(t('delete'), $this->path . '/' . $id . '/delete', array(
      'query' => drupal_get_destination(),
    ));
    return $row;
  }

  /**
   * Overrides EntityDefaultUIController::overviewTableRow().
   */
  public function applyOperation($op, $entity) {

    // If the default scope is about to be deleted, reset the server setting.
    if ($op == 'delete') {
      $server = oauth2_server_load(arg(4));
      if ($server && $server->settings['default_scope'] == $entity->name) {
        $server->settings['default_scope'] = '';
        $server
          ->save();
      }
    }
    return parent::applyOperation($op, $entity);
  }

}

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::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.
OAuth2ServerScopeUIController::applyOperation public function Overrides EntityDefaultUIController::overviewTableRow(). Overrides EntityDefaultUIController::applyOperation
OAuth2ServerScopeUIController::hook_menu public function Overrides EntityDefaultUIController::hook_menu(). Overrides EntityDefaultUIController::hook_menu
OAuth2ServerScopeUIController::overviewTable public function Overrides EntityDefaultUIController::overviewTable(). Overrides EntityDefaultUIController::overviewTable
OAuth2ServerScopeUIController::overviewTableHeaders protected function Overrides EntityDefaultUIController::overviewTableHeaders(). Overrides EntityDefaultUIController::overviewTableHeaders
OAuth2ServerScopeUIController::overviewTableRow protected function Overrides EntityDefaultUIController::overviewTableRow(). Overrides EntityDefaultUIController::overviewTableRow
OAuth2ServerScopeUIController::__construct public function Overrides EntityDefaultUIController::__construct