You are here

class IsExcludedImageStyle in Acquia Lift Connector 8.4

Class IsExcludedImageStyle.

Prevents to enqueue some image styles.

@package Drupal\acquia_lift_publisher\EventSubscriber\EnqueueEligibility

Hierarchy

  • class \Drupal\acquia_lift_publisher\EventSubscriber\EnqueueEligibility\IsExcludedImageStyle implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of IsExcludedImageStyle

1 string reference to 'IsExcludedImageStyle'
acquia_lift_publisher.services.yml in modules/acquia_lift_publisher/acquia_lift_publisher.services.yml
modules/acquia_lift_publisher/acquia_lift_publisher.services.yml
1 service uses IsExcludedImageStyle
excluded_image_style.enqueue in modules/acquia_lift_publisher/acquia_lift_publisher.services.yml
Drupal\acquia_lift_publisher\EventSubscriber\EnqueueEligibility\IsExcludedImageStyle

File

modules/acquia_lift_publisher/src/EventSubscriber/EnqueueEligibility/IsExcludedImageStyle.php, line 18

Namespace

Drupal\acquia_lift_publisher\EventSubscriber\EnqueueEligibility
View source
class IsExcludedImageStyle implements EventSubscriberInterface {

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

  /**
   * Reacts on ContentHubPublisherEvents::ENQUEUE_CANDIDATE_ENTITY event.
   *
   * @param \Drupal\acquia_contenthub_publisher\Event\ContentHubEntityEligibilityEvent $event
   *   Event.
   *
   * @throws \Exception
   */
  public function onEnqueueCandidateEntity(ContentHubEntityEligibilityEvent $event) {
    $entity = $event
      ->getEntity();
    if (FALSE == $this
      ->isExcluded($entity)) {
      return;
    }
    $event
      ->setEligibility(FALSE);
    $event
      ->stopPropagation();
  }

  /**
   * Checks if current entity must be excluded from export queue.
   *
   * @param \Drupal\Core\Entity\EntityInterface $entity
   *   Entity.
   *
   * @return bool
   *   TRUE if entity is image style from acquia_lift_publisher module.
   */
  protected function isExcluded(EntityInterface $entity) {
    if (FALSE === $entity instanceof ImageStyle) {
      return FALSE;
    }
    $excluded_items = [
      'acquia_lift_publisher_preview_image',
    ];
    return in_array($entity
      ->getOriginalId(), $excluded_items);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
IsExcludedImageStyle::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
IsExcludedImageStyle::isExcluded protected function Checks if current entity must be excluded from export queue.
IsExcludedImageStyle::onEnqueueCandidateEntity public function Reacts on ContentHubPublisherEvents::ENQUEUE_CANDIDATE_ENTITY event.