class PathAliasExists
Provides a 'Path alias exists' condition.
@todo Add access callback information from Drupal 7.
Plugin annotation
@Condition(
id = "rules_path_alias_exists",
label = @Translation("Path alias exists"),
category = @Translation("Path"),
provider = "path_alias",
context_definitions = {
"alias" = @ContextDefinition("string",
label = @Translation("Path alias"),
description = @Translation("Specify the path alias to check for. For example, '/about' for an about page.")
),
"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\PathAliasExists 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 PathAliasExists
File
-
src/
Plugin/ Condition/ PathAliasExists.php, line 36
Namespace
Drupal\rules\Plugin\ConditionView source
class PathAliasExists extends RulesConditionBase implements ContainerFactoryPluginInterface {
/**
* The alias manager service.
*
* @var \Drupal\path_alias\AliasManagerInterface
*/
protected $aliasManager;
/**
* Constructs a PathAliasExists 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 path alias exists.
*
* @param string $alias
* The alias to see if exists.
* @param \Drupal\Core\Language\LanguageInterface|null $language
* The language to use.
*
* @return bool
* TRUE if the system path does not match the given alias (ie: the alias
* exists).
*/
protected function doEvaluate($alias, LanguageInterface $language = NULL) {
$langcode = is_null($language) ? NULL : $language->getId();
$path = $this->aliasManager
->getPathByAlias($alias, $langcode);
// getPathByAlias() returns the alias if there is no path.
return $path != $alias;
}
}