class Alias in Content Synchronization 8.2
Same name and namespace in other branches
- 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
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\content_sync\Plugin\SyncNormalizerDecoratorBase implements SyncNormalizerDecoratorInterface
- class \Drupal\content_sync\Plugin\SyncNormalizerDecorator\Alias implements ContainerFactoryPluginInterface
- class \Drupal\content_sync\Plugin\SyncNormalizerDecoratorBase implements SyncNormalizerDecoratorInterface
Expanded class hierarchy of Alias
File
- src/
Plugin/ SyncNormalizerDecorator/ Alias.php, line 20
Namespace
Drupal\content_sync\Plugin\SyncNormalizerDecoratorView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Alias:: |
protected | property | ||
Alias:: |
public static | function |
Overrides ContainerFactoryPluginInterface:: |
|
Alias:: |
public | function |
Overrides SyncNormalizerDecoratorBase:: |
|
Alias:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
SyncNormalizerDecoratorBase:: |
public | function |
Apply decoration for the denormalization process. Overrides SyncNormalizerDecoratorInterface:: |
|
SyncNormalizerDecoratorBase:: |
public | function |
Apply decoration to the entity after the denormalization process is done. Overrides SyncNormalizerDecoratorInterface:: |