function ThemeSettingsForm::validatePath

Same name in other branches
  1. 8.9.x core/modules/system/src/Form/ThemeSettingsForm.php \Drupal\system\Form\ThemeSettingsForm::validatePath()
  2. 10 core/modules/system/src/Form/ThemeSettingsForm.php \Drupal\system\Form\ThemeSettingsForm::validatePath()
  3. 11.x core/modules/system/src/Form/ThemeSettingsForm.php \Drupal\system\Form\ThemeSettingsForm::validatePath()

Helper function for the system_theme_settings form.

Attempts to validate normal system paths, paths relative to the public files directory, or stream wrapper URIs. If the given path is any of the above, returns a valid path or URI that the theme system can display.

Parameters

string $path: A path relative to the Drupal root or to the public files directory, or a stream wrapper URI.

Return value

mixed A valid path that can be displayed through the theme system, or FALSE if the path could not be validated.

2 calls to ThemeSettingsForm::validatePath()
ThemeSettingsForm::submitForm in core/modules/system/src/Form/ThemeSettingsForm.php
Form submission handler.
ThemeSettingsForm::validateForm in core/modules/system/src/Form/ThemeSettingsForm.php
Form validation handler.

File

core/modules/system/src/Form/ThemeSettingsForm.php, line 529

Class

ThemeSettingsForm
Displays theme configuration for entire site and individual themes.

Namespace

Drupal\system\Form

Code

protected function validatePath($path) {
    // Absolute local file paths are invalid.
    if ($this->fileSystem
        ->realpath($path) == $path) {
        return FALSE;
    }
    // A path relative to the Drupal root or a fully qualified URI is valid.
    if (is_file($path)) {
        return $path;
    }
    // Prepend 'public://' for relative file paths within public filesystem.
    if (StreamWrapperManager::getScheme($path) === FALSE) {
        $path = 'public://' . $path;
    }
    if (is_file($path)) {
        return $path;
    }
    return FALSE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.