public static function GroupContent::postDelete in Group 8
Same name and namespace in other branches
- 2.0.x src/Entity/GroupContent.php \Drupal\group\Entity\GroupContent::postDelete()
Acts on deleted entities before the delete hook is invoked.
Used after the entities are deleted but before invoking the delete hook.
Parameters
\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage object.
\Drupal\Core\Entity\EntityInterface[] $entities: An array of entities.
Overrides EntityBase::postDelete
File
- src/
Entity/ GroupContent.php, line 211
Class
- GroupContent
- Defines the Group content entity.
Namespace
Drupal\group\EntityCode
public static function postDelete(EntityStorageInterface $storage, array $entities) {
parent::postDelete($storage, $entities);
/** @var GroupContentInterface[] $entities */
foreach ($entities as $group_content) {
if ($entity = $group_content
->getEntity()) {
// For the same reasons we re-save entities that are added to a group,
// we need to re-save entities that were removed from one. See
// ::postSave(). We only save the entity if it still exists to avoid
// trying to save an entity that just got deleted and triggered the
// deletion of its group content entities.
// @todo Revisit when https://www.drupal.org/node/2754399 lands.
$entity
->save();
// If a membership gets deleted, we need to reset the internal group
// roles cache for the member in that group, but only if the user still
// exists. Otherwise, it doesn't matter as the user ID will become void.
if ($group_content
->getContentPlugin()
->getPluginId() == 'group_membership') {
/** @var \Drupal\group\Entity\Storage\GroupRoleStorageInterface $role_storage */
$role_storage = \Drupal::entityTypeManager()
->getStorage('group_role');
$role_storage
->resetUserGroupRoleCache($group_content
->getEntity(), $group_content
->getGroup());
}
}
}
}