You are here

class FileSchemeIsSupported in Acquia Content Hub 8.2

Prevents enqueueing files whose scheme is not supported.

Hierarchy

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

Expanded class hierarchy of FileSchemeIsSupported

1 file declares its use of FileSchemeIsSupported
UnsupportedFileSchemeTest.php in modules/acquia_contenthub_publisher/tests/src/Unit/EventSubscriber/EntityEligibility/UnsupportedFileSchemeTest.php
1 string reference to 'FileSchemeIsSupported'
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 FileSchemeIsSupported
file_scheme_is_supported.enqueue in modules/acquia_contenthub_publisher/acquia_contenthub_publisher.services.yml
Drupal\acquia_contenthub_publisher\EventSubscriber\EnqueueEligibility\FileSchemeIsSupported

File

modules/acquia_contenthub_publisher/src/EventSubscriber/EnqueueEligibility/FileSchemeIsSupported.php, line 14

Namespace

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

  /**
   * The File Scheme Handler Manager Interface.
   *
   * @var \Drupal\acquia_contenthub\Plugin\FileSchemeHandler\FileSchemeHandlerManagerInterface
   */
  protected $fileSchemeHandler;

  /**
   * ImportedEntity constructor.
   *
   * @param \Drupal\acquia_contenthub\Plugin\FileSchemeHandler\FileSchemeHandlerManagerInterface $file_scheme_handler
   *   The File Scheme Handler Manager Interface.
   */
  public function __construct(FileSchemeHandlerManagerInterface $file_scheme_handler) {
    $this->fileSchemeHandler = $file_scheme_handler;
  }

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

  /**
   * Prevent files with unsupported schemes to be enqueued.
   *
   * @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 an unsupported scheme then do not export it.
    $entity = $event
      ->getEntity();
    if ($entity instanceof FileInterface && !$this->fileSchemeHandler
      ->isSupportedFileScheme($entity)) {
      $event
        ->setEligibility(FALSE);
      $event
        ->stopPropagation();
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FileSchemeIsSupported::$fileSchemeHandler protected property The File Scheme Handler Manager Interface.
FileSchemeIsSupported::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
FileSchemeIsSupported::onEnqueueCandidateEntity public function Prevent files with unsupported schemes to be enqueued.
FileSchemeIsSupported::__construct public function ImportedEntity constructor.