function ConfigBase::validateName

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Config/ConfigBase.php \Drupal\Core\Config\ConfigBase::validateName()
  2. 8.9.x core/lib/Drupal/Core/Config/ConfigBase.php \Drupal\Core\Config\ConfigBase::validateName()
  3. 11.x core/lib/Drupal/Core/Config/ConfigBase.php \Drupal\Core\Config\ConfigBase::validateName()

Validates the configuration object name.

Parameters

string $name: The name of the configuration object.

Throws

\Drupal\Core\Config\ConfigNameException

See also

Config::MAX_NAME_LENGTH

1 call to ConfigBase::validateName()
Config::save in core/lib/Drupal/Core/Config/Config.php
Saves the configuration object.

File

core/lib/Drupal/Core/Config/ConfigBase.php, line 94

Class

ConfigBase
Provides a base class for configuration objects with get/set support.

Namespace

Drupal\Core\Config

Code

public static function validateName($name) {
    // The name must be namespaced by owner.
    if (!str_contains($name, '.')) {
        throw new ConfigNameException("Missing namespace in Config object name {$name}.");
    }
    // The name must be shorter than Config::MAX_NAME_LENGTH characters.
    if (strlen($name) > self::MAX_NAME_LENGTH) {
        throw new ConfigNameException("Config object name {$name} exceeds maximum allowed length of " . static::MAX_NAME_LENGTH . " characters.");
    }
    // The name must not contain any of the following characters:
    // : ? * < > " ' / \
    if (preg_match('/[:?*<>"\'\\/\\\\]/', $name)) {
        throw new ConfigNameException("Invalid character in Config object name {$name}.");
    }
}

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