diff --git a/core/lib/Drupal/Core/Condition/ConditionManager.php b/core/lib/Drupal/Core/Condition/ConditionManager.php index 9e5a471..1eb8a47 100644 --- a/core/lib/Drupal/Core/Condition/ConditionManager.php +++ b/core/lib/Drupal/Core/Condition/ConditionManager.php @@ -8,13 +8,13 @@ namespace Drupal\Core\Condition; use Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator; +use Drupal\Component\Plugin\Factory\DefaultFactory; use Drupal\Component\Plugin\PluginManagerBase; use Drupal\Core\Executable\ExecutableInterface; use Drupal\Core\Executable\ExecutableManagerInterface; use Drupal\Core\Plugin\Discovery\AlterDecorator; use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; use Drupal\Core\Plugin\Discovery\CacheDecorator; -use Drupal\Core\Plugin\Factory\ContainerFactory; /** * A plugin manager for condition plugins. @@ -34,7 +34,7 @@ public function __construct(\Traversable $namespaces) { $this->discovery = new AlterDecorator($this->discovery, 'condition_info'); $this->discovery = new CacheDecorator($this->discovery, 'condition:' . language(LANGUAGE_TYPE_INTERFACE)->langcode); - $this->factory = new ContainerFactory($this); + $this->factory = new DefaultFactory($this); } /** diff --git a/core/lib/Drupal/Core/Plugin/Factory/ContainerFactory.php b/core/lib/Drupal/Core/Plugin/Factory/ContainerFactory.php index 3960524..cdf6f49 100644 --- a/core/lib/Drupal/Core/Plugin/Factory/ContainerFactory.php +++ b/core/lib/Drupal/Core/Plugin/Factory/ContainerFactory.php @@ -19,13 +19,7 @@ class ContainerFactory extends DefaultFactory { public function createInstance($plugin_id, array $configuration) { $plugin_definition = $this->discovery->getDefinition($plugin_id); $plugin_class = static::getPluginClass($plugin_id, $plugin_definition); - $class = new \ReflectionClass($plugin_class); - if ($class->hasMethod('create')) { - return $plugin_class::create(\Drupal::getContainer(), $configuration, $plugin_id, $plugin_definition); - } - else { - return parent::createInstance($plugin_id, $configuration); - } + return $plugin_class::create(\Drupal::getContainer(), $configuration, $plugin_id, $plugin_definition); } } diff --git a/core/modules/system/lib/Drupal/system/Plugin/Condition/RequestPath.php b/core/modules/system/lib/Drupal/system/Plugin/Condition/RequestPath.php index dc8baed..3476d71 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/Condition/RequestPath.php +++ b/core/modules/system/lib/Drupal/system/Plugin/Condition/RequestPath.php @@ -26,6 +26,12 @@ * context = { * "request" = { * "class" = "Symfony\Component\HttpFoundation\Request" + * }, + * "alias_manager" = { + * "class" = "Drupal\Core\Path\AliasManagerInterface" + * }, + * "path_matcher" = { + * "class" = "Drupal\Core\Path\PathMatcherInterface" * } * } * ) @@ -33,56 +39,6 @@ class RequestPath extends ConditionPluginBase { /** - * The path matcher. - * - * @var \Drupal\Core\Path\PathMatcherInterface - */ - protected $pathMatcher; - - /** - * The alias manager. - * - * @var \Drupal\Core\Path\AliasManagerInterface - */ - protected $aliasManager; - - /** - * Constructs a new RequestPath condition plugin. - * - * @param PathMatcherInterface $path_matcher - * The path matcher. - * @param AliasManagerInterface $alias_manager - * The alias manager. - * {@inheritdoc} - */ - public function __construct(PathMatcherInterface $path_matcher, AliasManagerInterface $alias_manager, array $configuration, $plugin_id, array $plugin_definition) { - $this->pathMatcher = $path_matcher; - $this->aliasManager = $alias_manager; - parent::__construct($configuration, $plugin_id, $plugin_definition); - } - - /** - * Creates an instance of the plugin. - * - * This is a factory method that returns a new instance of this object. The - * factory should pass any needed dependencies into the constructor of this - * object, but not the container itself. - * - * @param ContainerInterface $container - * The service container this object should use. - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, array $plugin_definition) { - return new static( - $container->get('path_matcher'), - $container->get('path.alias_manager'), - $configuration, - $plugin_id, - $plugin_definition - ); - } - - /** * {@inheritdoc} */ public function form($form, &$form_state) { @@ -127,10 +83,12 @@ public function evaluate() { $pages = Unicode::strtolower($this->configuration['pages']); // Compare the lowercase path alias (if any) and internal path. $request = $this->getContextValue('request'); + $pathMatcher = $this->getContextValue('path_matcher'); + $aliasManager = $this->getContextValue('alias_manager'); $path = $request->attributes->get('system_path'); - $path_alias = Unicode::strtolower($this->aliasManager->getPathAlias($path)); + $path_alias = Unicode::strtolower($aliasManager->getPathAlias($path)); - return $this->pathMatcher->matchPath($path_alias, $pages) || (($path != $path_alias) && $this->pathMatcher->matchPath($path, $pages)); + return $pathMatcher->matchPath($path_alias, $pages) || (($path != $path_alias) && $pathMatcher->matchPath($path, $pages)); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Condition/RequestPathConditionTest.php b/core/modules/system/lib/Drupal/system/Tests/Condition/RequestPathConditionTest.php index e50f93b..8bf71d8 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Condition/RequestPathConditionTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Condition/RequestPathConditionTest.php @@ -56,7 +56,9 @@ public function testConditions() { $pages = "my/pass/page\r\nmy/pass/page2"; $condition = $this->manager->createInstance('request_path') ->setConfig('pages', $pages) - ->setContextValue('request', $new_request); + ->setContextValue('request', $new_request) + ->setContextValue('alias_manager', $this->container->get('path.alias_manager')) + ->setContextValue('path_matcher', $this->container->get('path_matcher')); // Check the first configured path and summary. $this->assertTrue($condition->execute(), 'The system_path my/pass/page passes.');