function UrlHelperFormatConstraint::check

File

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

Class

UrlHelperFormatConstraint
Defines a custom format constraint for json-schema.

Namespace

Drupal\Tests\Core\Theme\Component

Code

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(ConstraintError::FORMAT_URL, $path, [
        'format' => $schema->format,
      ]);
    }
    return;
  }
  parent::check($element, $schema, $path, $i);
}

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