function FundamentalCompatibilityConstraintValidator::validate

Same name in other branches
  1. 10 core/modules/ckeditor5/src/Plugin/Validation/Constraint/FundamentalCompatibilityConstraintValidator.php \Drupal\ckeditor5\Plugin\Validation\Constraint\FundamentalCompatibilityConstraintValidator::validate()
  2. 11.x core/modules/ckeditor5/src/Plugin/Validation/Constraint/FundamentalCompatibilityConstraintValidator.php \Drupal\ckeditor5\Plugin\Validation\Constraint\FundamentalCompatibilityConstraintValidator::validate()

Throws

\Symfony\Component\Validator\Exception\UnexpectedTypeException Thrown when the given constraint is not supported by this validator.

File

core/modules/ckeditor5/src/Plugin/Validation/Constraint/FundamentalCompatibilityConstraintValidator.php, line 55

Class

FundamentalCompatibilityConstraintValidator
Validates fundamental compatibility of CKEditor 5 with the given text format.

Namespace

Drupal\ckeditor5\Plugin\Validation\Constraint

Code

public function validate($toolbar_item, Constraint $constraint) {
    if (!$constraint instanceof FundamentalCompatibilityConstraint) {
        throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\\FundamentalCompatibility');
    }
    $text_editor = $this->createTextEditorObjectFromContext();
    // First: the two fundamental checks against the text format. If any of
    // them adds a constraint violation, return early, because it is a
    // fundamental compatibility problem.
    $this->checkNoMarkupFilters($text_editor->getFilterFormat(), $constraint);
    if ($this->context
        ->getViolations()
        ->count() > 0) {
        return;
    }
    $this->checkHtmlRestrictionsAreCompatible($text_editor->getFilterFormat(), $constraint);
    if ($this->context
        ->getViolations()
        ->count() > 0) {
        return;
    }
    // Second: ensure that all tags can actually be created.
    $this->checkAllHtmlTagsAreCreatable($text_editor, $constraint);
    // Finally: ensure the CKEditor 5 configuration's ability to generate HTML
    // markup precisely matches that of the text format.
    $this->checkHtmlRestrictionsMatch($text_editor, $constraint);
}

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