You are here

public static function YamlForm::preDelete in YAML Form 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/YamlForm.php, line 1141

Class

YamlForm
Defines the form entity.

Namespace

Drupal\yamlform\Entity

Code

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

  /** @var \Drupal\yamlform\YamlFormInterface[] $entities */
  parent::preDelete($storage, $entities);

  // Delete all paths and states associated with this form.
  foreach ($entities as $entity) {

    // Delete all paths.
    $entity
      ->deletePaths();

    // Delete the state.
    \Drupal::state()
      ->delete('yamlform.yamlform.' . $entity
      ->id());
  }

  // Delete all submission associated with this form.
  $submission_ids = \Drupal::entityQuery('yamlform_submission')
    ->condition('yamlform_id', array_keys($entities), 'IN')
    ->sort('sid')
    ->execute();
  $submission_storage = \Drupal::entityTypeManager()
    ->getStorage('yamlform_submission');
  $submissions = $submission_storage
    ->loadMultiple($submission_ids);
  $submission_storage
    ->delete($submissions);
}