class DisablePathauto in Acquia Content Hub 8.2
Disables path auto during pre-entity save.
@package Drupal\acquia_contenthub\EventSubscriber\PreEntitySave
Hierarchy
- class \Drupal\acquia_contenthub\EventSubscriber\PreEntitySave\DisablePathauto implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of DisablePathauto
1 string reference to 'DisablePathauto'
1 service uses DisablePathauto
File
- src/
EventSubscriber/ PreEntitySave/ DisablePathauto.php, line 16
Namespace
Drupal\acquia_contenthub\EventSubscriber\PreEntitySaveView source
class DisablePathauto implements EventSubscriberInterface {
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $handler;
/**
* DisablePathauto constructor.
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface $handler
* The module handler.
*/
public function __construct(ModuleHandlerInterface $handler) {
$this->handler = $handler;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[AcquiaContentHubEvents::PRE_ENTITY_SAVE] = 'onPreEntitySave';
return $events;
}
/**
* Turn off pathauto alias generation for entities being imported.
*
* @param \Drupal\acquia_contenthub\PreEntitySaveEvent $event
* The pre entity save event.
*/
public function onPreEntitySave(PreEntitySaveEvent $event) {
$entity = $event
->getEntity();
if ($this->handler
->moduleExists('pathauto') && $entity instanceof ContentEntityInterface && $entity
->hasField('path')) {
$entity->path->pathauto = 0;
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DisablePathauto:: |
protected | property | The module handler. | |
DisablePathauto:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
DisablePathauto:: |
public | function | Turn off pathauto alias generation for entities being imported. | |
DisablePathauto:: |
public | function | DisablePathauto constructor. |