class PathHasAlias
Provides a 'Path has alias' condition.
@todo Add access callback information from Drupal 7.
Plugin annotation
@Condition(
id = "rules_path_has_alias",
label = @Translation("Path has alias"),
category = @Translation("Path"),
provider = "path_alias",
context_definitions = {
"path" = @ContextDefinition("string",
label = @Translation("Path"),
description = @Translation("Specifies the existing path you wish to check. For example, '/node/28' or '/forum/1'.")
),
"language" = @ContextDefinition("language",
label = @Translation("Language"),
description = @Translation("If specified, the language for which the URL alias applies."),
options_provider = "\Drupal\rules\TypedData\Options\LanguageOptions",
default_value = NULL,
required = FALSE
),
}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
- class \Drupal\Core\Executable\ExecutablePluginBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\Core\Executable\ExecutableInterface, \Drupal\Core\Cache\CacheableDependencyInterface, \Drupal\Core\Plugin\ContextAwarePluginInterface uses \Drupal\Core\Plugin\ContextAwarePluginTrait
- class \Drupal\Core\Condition\ConditionPluginBase extends \Drupal\Core\Executable\ExecutablePluginBase implements \Drupal\Core\Condition\ConditionInterface uses \Drupal\Core\Plugin\ContextAwarePluginAssignmentTrait
- class \Drupal\rules\Core\RulesConditionBase extends \Drupal\Core\Condition\ConditionPluginBase implements \Drupal\rules\Core\RulesConditionInterface uses \Drupal\rules\Context\ContextProviderTrait, \Drupal\rules\Core\ExecutablePluginTrait, \Drupal\rules\Core\ConfigurationAccessControlTrait
- class \Drupal\rules\Plugin\Condition\PathHasAlias extends \Drupal\rules\Core\RulesConditionBase implements \Drupal\Core\Plugin\ContainerFactoryPluginInterface
- class \Drupal\rules\Core\RulesConditionBase extends \Drupal\Core\Condition\ConditionPluginBase implements \Drupal\rules\Core\RulesConditionInterface uses \Drupal\rules\Context\ContextProviderTrait, \Drupal\rules\Core\ExecutablePluginTrait, \Drupal\rules\Core\ConfigurationAccessControlTrait
- class \Drupal\Core\Condition\ConditionPluginBase extends \Drupal\Core\Executable\ExecutablePluginBase implements \Drupal\Core\Condition\ConditionInterface uses \Drupal\Core\Plugin\ContextAwarePluginAssignmentTrait
- class \Drupal\Core\Executable\ExecutablePluginBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\Core\Executable\ExecutableInterface, \Drupal\Core\Cache\CacheableDependencyInterface, \Drupal\Core\Plugin\ContextAwarePluginInterface uses \Drupal\Core\Plugin\ContextAwarePluginTrait
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
Expanded class hierarchy of PathHasAlias
File
-
src/
Plugin/ Condition/ PathHasAlias.php, line 36
Namespace
Drupal\rules\Plugin\ConditionView source
class PathHasAlias extends RulesConditionBase implements ContainerFactoryPluginInterface {
/**
* The alias manager service.
*
* @var \Drupal\path_alias\AliasManagerInterface
*/
protected $aliasManager;
/**
* Constructs a PathHasAlias object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin ID for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\path_alias\AliasManagerInterface $alias_manager
* The alias manager service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, AliasManagerInterface $alias_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->aliasManager = $alias_manager;
}
/**
* {@inheritdoc}
*/
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'));
}
/**
* Check if a URL path has a URL alias.
*
* @param string $path
* The path to check.
* @param \Drupal\Core\Language\LanguageInterface|null $language
* An optional language to look up the path in.
*
* @return bool
* TRUE if the path has an alias in the given language.
*/
protected function doEvaluate($path, LanguageInterface $language = NULL) {
$langcode = is_null($language) ? NULL : $language->getId();
$alias = $this->aliasManager
->getAliasByPath($path, $langcode);
// getAliasByPath() returns the path if there is no alias.
return $alias != $path;
}
}