You are here

function og_og_role_delete in Organic groups 8

Implements hook_ENTITY_TYPE_delete() for OgRole entities.

File

./og.module, line 424

Code

function og_og_role_delete(OgRoleInterface $role) {
  $role_name = $role
    ->getName();

  /** @var \Drupal\system\ActionConfigEntityInterface[] $actions */
  $actions = Action::loadMultiple([
    'og_membership_add_single_role_action.' . $role_name,
    'og_membership_remove_single_role_action.' . $role_name,
  ]);

  // Only remove the actions when the role name is not used by any other roles.
  foreach (OgRole::loadMultiple() as $role) {
    if ($role
      ->getName() === $role_name) {
      return;
    }
  }
  foreach ($actions as $action) {
    $action
      ->delete();
  }
}