You are here

public static function MenuPositionRule::preDelete in Menu Position 8

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/MenuPositionRule.php, line 347

Class

MenuPositionRule
Defines the MenuPositionRule entity.

Namespace

Drupal\menu_position\Entity

Code

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

  // Iterate over entities being deleted and remove associated menu links.
  foreach ($entities as $entity) {
    if ($entity
      ->getMenuLink() !== NULL) {
      $entity
        ->menuLinkManager()
        ->removeDefinition($entity
        ->getMenuLink());
      $entity
        ->setMenuLink(NULL);
    }
  }
  parent::preDelete($storage, $entities);
}