Skip to content
Snippets Groups Projects
Commit 2b6ff211 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

Issue #2028145 by dawehner, ParisLiakos: Fixed Raw default argument still...

Issue #2028145 by dawehner, ParisLiakos: Fixed Raw default argument still calls drupal_get_path_alias().
parent e94b01e5
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -9,6 +9,9 @@
use Drupal\Component\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
use Drupal\Core\Path\AliasManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Default argument plugin to use the raw value from the URL.
......@@ -22,6 +25,54 @@
*/
class Raw extends ArgumentDefaultPluginBase {
/**
* The request object.
*
* @var \Symfony\Component\HttpFoundation\Request
*/
protected $request;
/**
* The alias manager.
*
* @var \Drupal\Core\Path\AliasManagerInterface
*/
protected $aliasManager;
/**
* Constructs a Raw 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 array $plugin_definition
* The plugin implementation definition.
* @param \Symfony\Component\HttpFoundation\Request $request
* The request object.
* @param \Drupal\Core\Path\AliasManagerInterface $alias_manager
* The alias manager.
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, Request $request, AliasManagerInterface $alias_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->request = $request;
$this->aliasManager = $alias_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, array $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('request'),
$container->get('path.alias_manager.cached')
);
}
protected function defineOptions() {
$options = parent::defineOptions();
$options['index'] = array('default' => '');
......@@ -50,12 +101,13 @@ public function buildOptionsForm(&$form, &$form_state) {
}
public function getArgument() {
$path = NULL;
$path = $this->request->attributes->get('system_path');
if ($this->options['use_alias']) {
$path = drupal_get_path_alias();
$path = $this->aliasManager->getPathAlias($path);
}
if ($arg = arg($this->options['index'], $path)) {
return $arg;
$args = explode('/', $path);
if (isset($args[$this->options['index']])) {
return $args[$this->options['index']];
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment