You are here

public function OAuth2ServerUIController::operationForm in OAuth2 Server 7

Overrides EntityDefaultUIController::operationForm().

Overrides EntityDefaultUIController::operationForm

File

includes/oauth2_server.server_admin.inc, line 51
Admin UI for servers.

Class

OAuth2ServerUIController
UI controller.

Code

public function operationForm($form, &$form_state, $entity, $op) {
  if ($op == 'delete') {
    $query = new EntityFieldQuery();
    $query
      ->entityCondition('entity_type', 'oauth2_server_scope');
    $query
      ->propertyCondition('server', $entity->name);
    $query
      ->count();
    $num_scopes = $query
      ->execute();
    $num_clients = 0;

    // If there's at least one scope, we know the delete can't proceed,
    // so no need to count clients.
    if ($num_scopes == 0) {
      $query = new EntityFieldQuery();
      $query
        ->entityCondition('entity_type', 'oauth2_server_client');
      $query
        ->propertyCondition('server', $entity->name);
      $query
        ->count();
      $num_clients = $query
        ->execute();
    }
    if ($num_scopes > 0 || $num_clients > 0) {
      drupal_set_message(t('This server has associated scopes and/or clients, it cannot be deleted.'), 'error');
      return array();
    }
  }
  return parent::operationForm($form, $form_state, $entity, $op);
}