You are here

class FileIsTemporary in Acquia Content Hub 8.2

Subscribes to entity eligibility to prevent enqueueing temporary files.

Hierarchy

  • class \Drupal\acquia_contenthub_publisher\EventSubscriber\EnqueueEligibility\FileIsTemporary implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of FileIsTemporary

1 string reference to 'FileIsTemporary'
acquia_contenthub_publisher.services.yml in modules/acquia_contenthub_publisher/acquia_contenthub_publisher.services.yml
modules/acquia_contenthub_publisher/acquia_contenthub_publisher.services.yml
1 service uses FileIsTemporary
file_is_temporary.enqueue in modules/acquia_contenthub_publisher/acquia_contenthub_publisher.services.yml
Drupal\acquia_contenthub_publisher\EventSubscriber\EnqueueEligibility\FileIsTemporary

File

modules/acquia_contenthub_publisher/src/EventSubscriber/EnqueueEligibility/FileIsTemporary.php, line 13

Namespace

Drupal\acquia_contenthub_publisher\EventSubscriber\EnqueueEligibility
View source
class FileIsTemporary implements EventSubscriberInterface {

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[ContentHubPublisherEvents::ENQUEUE_CANDIDATE_ENTITY][] = [
      'onEnqueueCandidateEntity',
      50,
    ];
    return $events;
  }

  /**
   * Prevent temporary files from enqueueing.
   *
   * @param \Drupal\acquia_contenthub_publisher\Event\ContentHubEntityEligibilityEvent $event
   *   The event to determine entity eligibility.
   *
   * @throws \Exception
   */
  public function onEnqueueCandidateEntity(ContentHubEntityEligibilityEvent $event) {

    // If this is a file with status = 0 (TEMPORARY FILE) do not export it.
    // This is a check to avoid exporting temporary files.
    $entity = $event
      ->getEntity();
    if ($entity instanceof FileInterface && $entity
      ->isTemporary()) {
      $event
        ->setEligibility(FALSE);
      $event
        ->stopPropagation();
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FileIsTemporary::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
FileIsTemporary::onEnqueueCandidateEntity public function Prevent temporary files from enqueueing.