You are here

public function GroupHierarchyManager::removeSubgroup in Subgroup (Graph) 1.0.x

Removes the relationship of a subgroup.

Parameters

\Drupal\group\Entity\GroupContentInterface $group_content: The group content representing the subgroup relationship.

Overrides GroupHierarchyManagerInterface::removeSubgroup

File

src/GroupHierarchyManager.php, line 87

Class

GroupHierarchyManager
Manages the relationship between groups (as subgroups).

Namespace

Drupal\ggroup

Code

public function removeSubgroup(GroupContentInterface $group_content) {
  $plugin = $group_content
    ->getContentPlugin();
  if ($plugin
    ->getEntityTypeId() !== 'group') {
    throw new \InvalidArgumentException('Given group content entity does not represent a subgroup relationship.');
  }
  $parent_group = $group_content
    ->getGroup();
  $child_group_id = $group_content
    ->get('entity_id')
    ->getValue();
  if (!empty($child_group_id)) {
    $child_group_id = reset($child_group_id)['target_id'];
    $this->groupGraphStorage
      ->removeEdge($parent_group
      ->id(), $child_group_id);
  }

  // @todo Invalidate some kind of cache?
}