You are here

public function Server::delete in OAuth2 Server 2.0.x

Same name and namespace in other branches
  1. 8 src/Entity/Server.php \Drupal\oauth2_server\Entity\Server::delete()

Deletes an entity permanently.

Throws

\Drupal\Core\Entity\EntityStorageException In case of failures an exception is thrown.

Overrides EntityBase::delete

File

src/Entity/Server.php, line 170

Class

Server
Defines the OAuth2 server entity.

Namespace

Drupal\oauth2_server\Entity

Code

public function delete() {
  parent::delete();

  // Clean up scopes.

  /** @var \Drupal\oauth2_server\ScopeInterface[] $scopes */
  $scopes = $this
    ->entityTypeManager()
    ->getStorage('oauth2_server_scope')
    ->loadByProperties([
    'server_id' => $this
      ->id(),
  ]);
  foreach ($scopes as $scope) {
    $scope
      ->delete();
  }

  // Clean up clients.

  /** @var \Drupal\oauth2_server\ClientInterface[] $clients */
  $clients = $this
    ->entityTypeManager()
    ->getStorage('oauth2_server_client')
    ->loadByProperties([
    'server_id' => $this
      ->id(),
  ]);
  foreach ($clients as $client) {
    $client
      ->delete();
  }
}