Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. PathPluginBase.php

function 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 494

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 = [];
    if (str_starts_with($path, '%')) {
        $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. Use plain placeholders (%).");
    }
    return $errors;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal