You are here

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'
acquia_contenthub.services.yml in ./acquia_contenthub.services.yml
acquia_contenthub.services.yml
1 service uses DisablePathauto
pathauto_disable.pre_entity_save in ./acquia_contenthub.services.yml
Drupal\acquia_contenthub\EventSubscriber\PreEntitySave\DisablePathauto

File

src/EventSubscriber/PreEntitySave/DisablePathauto.php, line 16

Namespace

Drupal\acquia_contenthub\EventSubscriber\PreEntitySave
View 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

Namesort descending Modifiers Type Description Overrides
DisablePathauto::$handler protected property The module handler.
DisablePathauto::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
DisablePathauto::onPreEntitySave public function Turn off pathauto alias generation for entities being imported.
DisablePathauto::__construct public function DisablePathauto constructor.