class OAuth2ServerScopeUIController in OAuth2 Server 7
UI controller.
Hierarchy
- class \EntityDefaultUIController
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);
}
}