class UrlHelperFormatConstraint

Defines a custom format constraint for json-schema.

Hierarchy

Expanded class hierarchy of UrlHelperFormatConstraint

File

core/tests/Drupal/Tests/Core/Theme/Component/ComponentValidatorTest.php, line 294

Namespace

Drupal\Tests\Core\Theme\Component
View source
class UrlHelperFormatConstraint extends FormatConstraint {
    
    /**
     * {@inheritdoc}
     */
    public function check(&$element, $schema = NULL, ?JsonPointer $path = NULL, $i = NULL) : void {
        if (!isset($schema->format) || $this->factory
            ->getConfig(self::CHECK_MODE_DISABLE_FORMAT)) {
            return;
        }
        if ($schema->format === 'uri') {
            if (\is_string($element) && !UrlHelper::isValid($element)) {
                $this->addError($path, 'Invalid URL format', 'format', [
                    'format' => $schema->format,
                ]);
            }
            return;
        }
        parent::check($element, $schema, $path, $i);
    }

}

Members

Title Sort descending Modifiers Object type Summary
UrlHelperFormatConstraint::check public function

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