You are here

public static function FlagForList::preDelete in Flag Lists 4.0.x

Same name and namespace in other branches
  1. 8 src/Entity/FlagForList.php \Drupal\flag_lists\Entity\FlagForList::preDelete()

Acts on entities before they are deleted and before hooks are invoked.

Used before the entities are deleted and 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 ConfigEntityBase::preDelete

File

src/Entity/FlagForList.php, line 124

Class

FlagForList
Defines the Flag for list entity.

Namespace

Drupal\flag_lists\Entity

Code

public static function preDelete(EntityStorageInterface $storage, array $entities) {

  // If a Flag For List is removed also remove the Flag this is based on.
  $flagService = \Drupal::service('flag');
  foreach ($entities as $entity) {
    $flag = $flagService
      ->getFlagById($entity
      ->getBaseFlag());

    // Make sure the flag entity exists.
    if (!empty($flag)) {
      $flag
        ->delete();
    }
  }
  parent::preDelete($storage, $entities);
}