You are here

public function LPManagedContent::delete in Opigno Learning path 8

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

Deletes the content from database.

Overrides EntityBase::delete

File

src/Entity/LPManagedContent.php, line 329

Class

LPManagedContent
Defines the Learning Path Content entity.

Namespace

Drupal\opigno_learning_path\Entity

Code

public function delete() {

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

  /** @var LPManagedLink[] $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();
}