You are here

class Alias in Content Synchronization 8.2

Same name and namespace in other branches
  1. 3.0.x src/Plugin/SyncNormalizerDecorator/Alias.php \Drupal\content_sync\Plugin\SyncNormalizerDecorator\Alias

Provides a decorator for setting the alias to entity.

Plugin annotation


@SyncNormalizerDecorator(
  id = "alias",
  name = @Translation("Alias"),
)

Hierarchy

Expanded class hierarchy of Alias

File

src/Plugin/SyncNormalizerDecorator/Alias.php, line 20

Namespace

Drupal\content_sync\Plugin\SyncNormalizerDecorator
View source
class Alias extends SyncNormalizerDecoratorBase implements ContainerFactoryPluginInterface {

  /**
   * @var \Drupal\path_alias\AliasManager
   */
  protected $aliasManager;
  public function __construct(array $configuration, $plugin_id, $plugin_definition, AliasManager $alias_manager) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->aliasManager = $alias_manager;
  }

  /**
   * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
   * @param array $configuration
   * @param $plugin_id
   * @param $plugin_definition
   *
   * @return static
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('path_alias.manager'));
  }

  /**
   * @param array $normalized_entity
   * @param \Drupal\Core\Entity\ContentEntityInterface $entity
   * @param $format
   * @param array $context
   */
  public function decorateNormalization(array &$normalized_entity, ContentEntityInterface $entity, $format, array $context = []) {
    if ($entity
      ->hasLinkTemplate('canonical')) {
      $url = $entity
        ->toUrl();
      if (!empty($url)) {
        $system_path = '/' . $url
          ->getInternalPath();
        $langcode = $entity
          ->language()
          ->getId();
        $path_alias = $this->aliasManager
          ->getAliasByPath($system_path, $langcode);
        if (!empty($path_alias) && $path_alias != $system_path) {
          $normalized_entity['path'] = [
            [
              'alias' => $path_alias,
            ],
          ];
        }
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Alias::$aliasManager protected property
Alias::create public static function Overrides ContainerFactoryPluginInterface::create
Alias::decorateNormalization public function Overrides SyncNormalizerDecoratorBase::decorateNormalization
Alias::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
SyncNormalizerDecoratorBase::decorateDenormalization public function Apply decoration for the denormalization process. Overrides SyncNormalizerDecoratorInterface::decorateDenormalization
SyncNormalizerDecoratorBase::decorateDenormalizedEntity public function Apply decoration to the entity after the denormalization process is done. Overrides SyncNormalizerDecoratorInterface::decorateDenormalizedEntity