You are here

protected function PathPluginBase::validatePath in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/views/src/Plugin/views/display/PathPluginBase.php \Drupal\views\Plugin\views\display\PathPluginBase::validatePath()

Validates the path of the display.

Parameters

string $path: The path to validate.

Return value

array A list of error strings.

2 calls to PathPluginBase::validatePath()
PathPluginBase::validate in core/modules/views/src/Plugin/views/display/PathPluginBase.php
Validate that the plugin is correct and can be saved.
PathPluginBase::validateOptionsForm in core/modules/views/src/Plugin/views/display/PathPluginBase.php
Validate the options form.

File

core/modules/views/src/Plugin/views/display/PathPluginBase.php, line 452
Contains \Drupal\views\Plugin\views\display\PathPluginBase.

Class

PathPluginBase
The base display plugin for path/callbacks. This is used for pages and feeds.

Namespace

Drupal\views\Plugin\views\display

Code

protected function validatePath($path) {
  $errors = array();
  if (strpos($path, '%') === 0) {
    $errors[] = $this
      ->t('"%" may not be used for the first segment of a path.');
  }
  $parsed_url = UrlHelper::parse($path);
  if (empty($parsed_url['path'])) {
    $errors[] = $this
      ->t('Path is empty.');
  }
  if (!empty($parsed_url['query'])) {
    $errors[] = $this
      ->t('No query allowed.');
  }
  if (!parse_url('internal:/' . $path)) {
    $errors[] = $this
      ->t('Invalid path. Valid characters are alphanumerics as well as "-", ".", "_" and "~".');
  }
  $path_sections = explode('/', $path);

  // Symfony routing does not allow to use numeric placeholders.
  // @see \Symfony\Component\Routing\RouteCompiler
  $numeric_placeholders = array_filter($path_sections, function ($section) {
    return preg_match('/^%(.*)/', $section, $matches) && is_numeric($matches[1]);
  });
  if (!empty($numeric_placeholders)) {
    $errors[] = $this
      ->t("Numeric placeholders may not be used. Please use plain placeholders (%).");
  }
  return $errors;
}