You are here

public function ContentLockPreEntityDelete::onPreEntityDelete in Acquia Content Hub 8

Deletes content locks on a particular entity.

Parameters

\Drupal\acquia_contenthub_audit\Event\AuditPreEntityDeleteEvent $event: The audit pre entity delete event object.

File

acquia_contenthub_audit/src/EventSubscriber/ContentLockPreEntityDelete.php, line 52

Class

ContentLockPreEntityDelete
Content lock that occurs pre-entity delete.

Namespace

Drupal\acquia_contenthub_audit\EventSubscriber

Code

public function onPreEntityDelete(AuditPreEntityDeleteEvent $event) {

  // If content_lock module is not enabled then exit inmediately.
  if (!$this->contentLock) {
    return;
  }
  $entity = $event
    ->getEntity();

  // If translation lock is enabled for this entity type, remove lock per
  // each language.
  if ($this->contentLock
    ->isTranslationLockEnabled($entity
    ->getEntityTypeId())) {
    $languages = $entity
      ->getTranslationLanguages();
    foreach (array_keys($languages) as $langcode) {

      // Release entity lock.
      $this->contentLock
        ->release($entity
        ->id(), $langcode, NULL, NULL, $entity
        ->getEntityTypeId());
    }
  }
  else {

    // Release entity lock.
    $this->contentLock
      ->release($entity
      ->id(), LanguageInterface::LANGCODE_NOT_SPECIFIED, NULL, NULL, $entity
      ->getEntityTypeId());
  }
}