You are here

public function IsPathAliasForUnpublishedContent::onEnqueueCandidateEntity in Acquia Content Hub 8.2

Prevent path aliases from enqueueing unpublished content.

Parameters

\Drupal\acquia_contenthub_publisher\Event\ContentHubEntityEligibilityEvent $event: The event to determine entity eligibility.

Throws

\Exception

File

modules/acquia_contenthub_publisher/src/EventSubscriber/EnqueueEligibility/IsPathAliasForUnpublishedContent.php, line 73

Class

IsPathAliasForUnpublishedContent
Subscribes to entity eligibility to prevent enqueueing path alias.

Namespace

Drupal\acquia_contenthub_publisher\EventSubscriber\EnqueueEligibility

Code

public function onEnqueueCandidateEntity(ContentHubEntityEligibilityEvent $event) {

  // Never export path alias dependencies that are not "published" .
  $entity = $event
    ->getEntity();
  if (!$entity instanceof PathAliasInterface) {
    return;
  }
  try {
    $params = $this->matcher
      ->match($entity
      ->getPath());
    foreach ($params['_raw_variables']
      ->keys() as $parameter) {
      if (!empty($params[$parameter])) {
        $entity_dependency = $params[$parameter];
        if ($entity_dependency instanceof EntityInterface && !$this->entityModeratedRevision
          ->isPublishedRevision($entity_dependency)) {
          $event
            ->setEligibility(FALSE);
          $event
            ->stopPropagation();
        }
      }
    }
  } catch (\Exception $e) {
    $this->achLoggerChannel
      ->error('Following error occurred while trying to get the matching entity for path alias with uuid: @uuid. Error: @error', [
      '@uuid' => $entity
        ->uuid(),
      '@error' => $e
        ->getMessage(),
    ]);

    // Set the eligibility false as this path alias is a problematic entity.
    $event
      ->setEligibility(FALSE);
    $event
      ->stopPropagation();
  }
}