You are here

IsNotContentModerationState.php in Acquia Content Hub 8.2

File

modules/acquia_contenthub_publisher/src/EventSubscriber/EnqueueEligibility/IsNotContentModerationState.php
View source
<?php

namespace Drupal\acquia_contenthub_publisher\EventSubscriber\EnqueueEligibility;

use Drupal\acquia_contenthub_publisher\ContentHubPublisherEvents;
use Drupal\acquia_contenthub_publisher\Event\ContentHubEntityEligibilityEvent;
use Drupal\content_moderation\Entity\ContentModerationState;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * Subscribes to entity eligibility to prevent enqueueing temporary files.
 */
class IsNotContentModerationState 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) {

    // Never export ContentModerationState entities.
    $entity = $event
      ->getEntity();
    if ($entity instanceof ContentModerationState) {
      $event
        ->setEligibility(FALSE);
      $event
        ->stopPropagation();
    }
  }

}

Classes

Namesort descending Description
IsNotContentModerationState Subscribes to entity eligibility to prevent enqueueing temporary files.