Commit 332fad7c authored by alexpott's avatar alexpott

Issue #2303361 by tim.plunkett, kim.pepper: Replace instances of deprecated...

Issue #2303361 by tim.plunkett, kim.pepper: Replace instances of deprecated drupal_valid_path with PathValidator.
parent db253b09
......@@ -96,20 +96,3 @@ function path_is_admin($path) {
return FALSE;
}
}
/**
* Checks a path exists and the current user has access to it.
*
* @param string $path
* The path to check.
*
* @return bool
* TRUE if it is a valid path AND the current user has access permission,
* FALSE otherwise.
*
* @deprecated Use \Drupal::service('path.validator')->isValid($path) service
* instead.
*/
function drupal_valid_path($path) {
return \Drupal::service('path.validator')->isValid($path);
}
......@@ -12,6 +12,7 @@
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Path\AliasManagerInterface;
use Drupal\Core\Path\AliasStorageInterface;
use Drupal\Core\Path\PathValidatorInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -40,6 +41,13 @@ abstract class PathFormBase extends FormBase {
*/
protected $aliasManager;
/**
* The path validator.
*
* @var \Drupal\Core\Path\PathValidatorInterface
*/
protected $pathValidator;
/**
* Constructs a new PathController.
*
......@@ -47,10 +55,13 @@ abstract class PathFormBase extends FormBase {
* The path alias storage.
* @param \Drupal\Core\Path\AliasManagerInterface $alias_manager
* The path alias manager.
* @param \Drupal\Core\Path\PathValidatorInterface $path_validator
* The path validator.
*/
public function __construct(AliasStorageInterface $alias_storage, AliasManagerInterface $alias_manager) {
public function __construct(AliasStorageInterface $alias_storage, AliasManagerInterface $alias_manager, PathValidatorInterface $path_validator) {
$this->aliasStorage = $alias_storage;
$this->aliasManager = $alias_manager;
$this->pathValidator = $path_validator;
}
/**
......@@ -59,7 +70,8 @@ public function __construct(AliasStorageInterface $alias_storage, AliasManagerIn
public static function create(ContainerInterface $container) {
return new static(
$container->get('path.alias_storage'),
$container->get('path.alias_manager')
$container->get('path.alias_manager'),
$container->get('path.validator')
);
}
......@@ -146,7 +158,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
if ($this->aliasStorage->aliasExists($alias, $langcode, $source)) {
$form_state->setErrorByName('alias', t('The alias %alias is already in use in this language.', array('%alias' => $alias)));
}
if (!drupal_valid_path($source)) {
if (!$this->pathValidator->isValid($source)) {
$form_state->setErrorByName('source', t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $source)));
}
}
......
......@@ -11,6 +11,7 @@
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Path\AliasManagerInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Path\PathValidatorInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -25,6 +26,13 @@ class SiteInformationForm extends ConfigFormBase {
*/
protected $aliasManager;
/**
* The path validator.
*
* @var \Drupal\Core\Path\PathValidatorInterface
*/
protected $pathValidator;
/**
* Constructs a SiteInformationForm object.
*
......@@ -32,11 +40,14 @@ class SiteInformationForm extends ConfigFormBase {
* The factory for configuration objects.
* @param \Drupal\Core\Path\AliasManagerInterface $alias_manager
* The path alias manager.
* @param \Drupal\Core\Path\PathValidatorInterface $path_validator
* The path validator.
*/
public function __construct(ConfigFactoryInterface $config_factory, AliasManagerInterface $alias_manager) {
public function __construct(ConfigFactoryInterface $config_factory, AliasManagerInterface $alias_manager, PathValidatorInterface $path_validator) {
parent::__construct($config_factory);
$this->aliasManager = $alias_manager;
$this->pathValidator = $path_validator;
}
/**
......@@ -45,7 +56,8 @@ public function __construct(ConfigFactoryInterface $config_factory, AliasManager
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
$container->get('path.alias_manager')
$container->get('path.alias_manager'),
$container->get('path.validator')
);
}
......@@ -143,7 +155,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
form_set_value($form['front_page']['site_frontpage'], $this->aliasManager->getPathByAlias($form_state->getValue('site_frontpage')), $form_state);
}
// Validate front page path.
if (!drupal_valid_path($form_state->getValue('site_frontpage'))) {
if (!$this->pathValidator->isValid($form_state->getValue('site_frontpage'))) {
$form_state->setErrorByName('site_frontpage', $this->t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state->getValue('site_frontpage'))));
}
// Get the normal paths of both error pages.
......@@ -154,11 +166,11 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
form_set_value($form['error_page']['site_404'], $this->aliasManager->getPathByAlias($form_state->getValue('site_404')), $form_state);
}
// Validate 403 error path.
if (!$form_state->isValueEmpty('site_403') && !drupal_valid_path($form_state->getValue('site_403'))) {
if (!$form_state->isValueEmpty('site_403') && !$this->pathValidator->isValid($form_state->getValue('site_403'))) {
$form_state->setErrorByName('site_403', $this->t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state->getValue('site_403'))));
}
// Validate 404 error path.
if (!$form_state->isValueEmpty('site_404') && !drupal_valid_path($form_state->getValue('site_404'))) {
if (!$form_state->isValueEmpty('site_404') && !$this->pathValidator->isValid($form_state->getValue('site_404'))) {
$form_state->setErrorByName('site_404', $this->t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state->getValue('site_404'))));
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment