You are here

class RevisionIsCurrent in Acquia Content Hub 8.2

Subscribes to entity eligibility to prevent enqueuing unpublished revisions.

Hierarchy

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

Expanded class hierarchy of RevisionIsCurrent

1 string reference to 'RevisionIsCurrent'
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 RevisionIsCurrent
revision_is_current.enqueue in modules/acquia_contenthub_publisher/acquia_contenthub_publisher.services.yml
Drupal\acquia_contenthub_publisher\EventSubscriber\EnqueueEligibility\RevisionIsCurrent

File

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

Namespace

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

  /**
   * The Entity Moderated Revision Service.
   *
   * @var \Drupal\acquia_contenthub_publisher\EntityModeratedRevision
   */
  protected $entityModeratedRevision;

  /**
   * ImportedEntity constructor.
   *
   * @param \Drupal\acquia_contenthub_publisher\EntityModeratedRevision $entity_moderated_revision
   *   Entity Moderated Revision Service.
   */
  public function __construct(EntityModeratedRevision $entity_moderated_revision) {
    $this->entityModeratedRevision = $entity_moderated_revision;
  }

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

  /**
   * Allows to enqueue only the current revision of an entity.
   *
   * @param \Drupal\acquia_contenthub_publisher\Event\ContentHubEntityEligibilityEvent $event
   *   The event to determine entity eligibility.
   *
   * @throws \Exception
   */
  public function onEnqueueCandidateEntity(ContentHubEntityEligibilityEvent $event) {
    $entity = $event
      ->getEntity();

    // If entity transitioned from published to unpublished state
    // then do not prevent export.
    if ($this->entityModeratedRevision
      ->isTransitionedToUnpublished($entity)) {
      return;
    }
    if (!$this->entityModeratedRevision
      ->isPublishedRevision($entity)) {

      // This revision has no published translation then do not syndicate.
      $event
        ->setEligibility(FALSE);
      $event
        ->stopPropagation();
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RevisionIsCurrent::$entityModeratedRevision protected property The Entity Moderated Revision Service.
RevisionIsCurrent::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
RevisionIsCurrent::onEnqueueCandidateEntity public function Allows to enqueue only the current revision of an entity.
RevisionIsCurrent::__construct public function ImportedEntity constructor.