sites_group_overrides-1.x-dev/src/PathautoGenerator.php

src/PathautoGenerator.php
<?php

declare(strict_types=1);

namespace Drupal\sites_group_overrides;

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\pathauto\PathautoGeneratorInterface;
use Drupal\sites_group\SitesGroupServiceInterface;
use Drupal\sites_group_overrides\SitesGroupOverridesServiceInterface;

/**
 * Decorator for the pathauto generator - integrate sites path aliasses.
 */
class PathautoGenerator implements PathautoGeneratorInterface {

  /**
   * Constructs a PathautoGenerator object.
   *
   * @param \Drupal\pathauto\PathautoGeneratorInterface $inner
   *   The decorated PathautoGenerator.
   * @param \Drupal\sites_group_overrides\SitesGroupOverridesServiceInterface $sitesGroupService
   *   The sites group service.
   */
  public function __construct(
    protected PathautoGeneratorInterface $inner,
    protected SitesGroupServiceInterface $sitesGroupService,
    protected SitesGroupOverridesServiceInterface $sitesGroupOverrideService,
  ) {}

  /**
   * {@inheritdoc}
   */
  public function resetCaches() {
    $this->inner->resetCaches();
  }

  /**
   * {@inheritdoc}
   */
  public function getPatternByEntity(EntityInterface $entity) {
    return $this->inner->getPatternByEntity($entity);
  }

  /**
   * {@inheritdoc}
   */
  public function createEntityAlias(EntityInterface $entity, $op) {
    return $this->inner->createEntityAlias($entity, $op);
  }

  /**
   * {@inheritdoc}
   */
  public function updateEntityAlias(EntityInterface $entity, $op, array $options = []) {
    // Apply overrides for alias generation.
    if ($entity instanceof ContentEntityInterface && $group_relationship = $this->sitesGroupService->getRelationship($entity)) {
      $entity = clone $entity;
      $entity = $this->sitesGroupOverrideService->syncFieldsToEntity($group_relationship, $entity);
    }
    return $this->inner->updateEntityAlias($entity, $op, $options);
  }
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc