You are here

public function OpignoGroupManagedContent::delete in Opigno group manager 8

Same name and namespace in other branches
  1. 3.x src/Entity/OpignoGroupManagedContent.php \Drupal\opigno_group_manager\Entity\OpignoGroupManagedContent::delete()

Deletes the content from database.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Core\Entity\EntityStorageException

Overrides EntityBase::delete

File

src/Entity/OpignoGroupManagedContent.php, line 446

Class

OpignoGroupManagedContent
Defines the Opigno Group Content entity.

Namespace

Drupal\opigno_group_manager\Entity

Code

public function delete() {

  // First, delete all the links associated to this content.
  $as_child_links = OpignoGroupManagedLink::loadByProperties([
    'group_id' => $this
      ->getGroupId(),
    'child_content_id' => $this
      ->id(),
  ]);
  $as_parent_links = OpignoGroupManagedLink::loadByProperties([
    'group_id' => $this
      ->getGroupId(),
    'parent_content_id' => $this
      ->id(),
  ]);

  /** @var OpignoGroupManagedLink[] $all_links */
  $all_links = array_merge($as_child_links, $as_parent_links);

  // TODO: Maybe use the entityStorage to bulk delete ?
  // Delete the links.
  foreach ($all_links as $link) {
    $link
      ->delete();
  }
  parent::delete();
}