class IsPathAliasForUnpublishedContent in Acquia Content Hub 8.2
Subscribes to entity eligibility to prevent enqueueing path alias.
Hierarchy
- class \Drupal\acquia_contenthub_publisher\EventSubscriber\EnqueueEligibility\IsPathAliasForUnpublishedContent implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of IsPathAliasForUnpublishedContent
1 file declares its use of IsPathAliasForUnpublishedContent
- IsPathAliasForUnpublishedContentTest.php in modules/
acquia_contenthub_publisher/ tests/ src/ Unit/ EventSubscriber/ EntityEligibility/ IsPathAliasForUnpublishedContentTest.php
1 string reference to 'IsPathAliasForUnpublishedContent'
- 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 IsPathAliasForUnpublishedContent
File
- modules/
acquia_contenthub_publisher/ src/ EventSubscriber/ EnqueueEligibility/ IsPathAliasForUnpublishedContent.php, line 17
Namespace
Drupal\acquia_contenthub_publisher\EventSubscriber\EnqueueEligibilityView source
class IsPathAliasForUnpublishedContent implements EventSubscriberInterface {
/**
* The url matcher.
*
* @var \Symfony\Component\Routing\Matcher\UrlMatcherInterface
*/
protected $matcher;
/**
* The Entity Moderated Revision Service.
*
* @var \Drupal\acquia_contenthub_publisher\EntityModeratedRevision
*/
protected $entityModeratedRevision;
/**
* The acquia_contenthub_publisher logger channel.
*
* @var \Drupal\Core\Logger\LoggerChannelInterface
*/
protected $achLoggerChannel;
/**
* IsPathAliasForUnpublishedContent constructor.
*
* @param \Symfony\Component\Routing\Matcher\UrlMatcherInterface $matcher
* URL Matcher service.
* @param \Drupal\acquia_contenthub_publisher\EntityModeratedRevision $entity_moderated_revision
* Entity Moderated Revision Service.
* @param \Drupal\Core\Logger\LoggerChannelInterface $logger_channel
* The acquia_contenthub_publisher logger channel.
*/
public function __construct(UrlMatcherInterface $matcher, EntityModeratedRevision $entity_moderated_revision, LoggerChannelInterface $logger_channel) {
$this->matcher = $matcher;
$this->entityModeratedRevision = $entity_moderated_revision;
$this->achLoggerChannel = $logger_channel;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[ContentHubPublisherEvents::ENQUEUE_CANDIDATE_ENTITY][] = [
'onEnqueueCandidateEntity',
50,
];
return $events;
}
/**
* Prevent path aliases from enqueueing unpublished content.
*
* @param \Drupal\acquia_contenthub_publisher\Event\ContentHubEntityEligibilityEvent $event
* The event to determine entity eligibility.
*
* @throws \Exception
*/
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();
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
IsPathAliasForUnpublishedContent:: |
protected | property | The acquia_contenthub_publisher logger channel. | |
IsPathAliasForUnpublishedContent:: |
protected | property | The Entity Moderated Revision Service. | |
IsPathAliasForUnpublishedContent:: |
protected | property | The url matcher. | |
IsPathAliasForUnpublishedContent:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
IsPathAliasForUnpublishedContent:: |
public | function | Prevent path aliases from enqueueing unpublished content. | |
IsPathAliasForUnpublishedContent:: |
public | function | IsPathAliasForUnpublishedContent constructor. |