function CKEditor5::validatePair
Same name in other branches
- 9 core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php \Drupal\ckeditor5\Plugin\Editor\CKEditor5::validatePair()
- 11.x core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php \Drupal\ckeditor5\Plugin\Editor\CKEditor5::validatePair()
Validates a Text Editor + Text Format pair.
Drupal is designed to only verify schema conformity (and validation) of individual config entities. The Text Editor module layers a tightly coupled Editor entity on top of the Filter module's FilterFormat config entity. This inextricable coupling is clearly visible in EditorInterface: \Drupal\editor\EditorInterface::getFilterFormat(). They are always paired. Because not every text editor is guaranteed to be compatible with every text format, the pair must be validated.
Parameters
\Drupal\editor\EditorInterface $text_editor: The paired text editor to validate.
\Drupal\filter\FilterFormatInterface $text_format: The paired text format to validate.
bool $all_compatibility_problems: Get all compatibility problems (default) or only fundamental ones.
Return value
\Symfony\Component\Validator\ConstraintViolationListInterface The validation constraint violations.
Throws
\InvalidArgumentException Thrown when the text editor is not configured to use CKEditor 5.
See also
\Drupal\editor\EditorInterface::getFilterFormat()
30 calls to CKEditor5::validatePair()
- AddedStylesheetsTest::setUp in core/
modules/ ckeditor5/ tests/ src/ Functional/ AddedStylesheetsTest.php - CKEditor5::validateConfigurationForm in core/
modules/ ckeditor5/ src/ Plugin/ Editor/ CKEditor5.php - Form validation handler.
- CKEditor5::validateSwitchingToCKEditor5 in core/
modules/ ckeditor5/ src/ Plugin/ Editor/ CKEditor5.php - Validate callback to inform the user of CKEditor 5 compatibility problems.
- CKEditor5DialogTest::testCKEditor5FocusInTooltipsInDialog in core/
modules/ ckeditor5/ tests/ src/ FunctionalJavascript/ CKEditor5DialogTest.php - Tests if CKEditor 5 tooltips can be interacted with in dialogs.
- CKEditor5MarkupTest::testAttributeEncoding in core/
modules/ ckeditor5/ tests/ src/ FunctionalJavascript/ CKEditor5MarkupTest.php - Ensures that attribute values are encoded.
File
-
core/
modules/ ckeditor5/ src/ Plugin/ Editor/ CKEditor5.php, line 210
Class
- CKEditor5
- Defines a CKEditor 5-based text editor for Drupal.
Namespace
Drupal\ckeditor5\Plugin\EditorCode
public static function validatePair(EditorInterface $text_editor, FilterFormatInterface $text_format, bool $all_compatibility_problems = TRUE) : ConstraintViolationListInterface {
if ($text_editor->getEditor() !== 'ckeditor5') {
throw new \InvalidArgumentException('This text editor is not configured to use CKEditor 5.');
}
$typed_config_manager = \Drupal::getContainer()->get('config.typed');
$typed_config = $typed_config_manager->createFromNameAndData('ckeditor5_valid_pair__format_and_editor', [
// A mix of:
// - editor.editor.*.settings — note that "settings" is top-level in
// editor.editor.*, and so it is here, so all validation constraints
// will continue to work fine.
'settings' => $text_editor->toArray()['settings'],
// - filter.format.*.filters — note that "filters" is top-level in
// filter.format.*, and so it is here, so all validation constraints
// will continue to work fine.
'filters' => $text_format->toArray()['filters'],
// - editor.editor.*.image_upload — note that "image_upload" is
// top-level in editor.editor.*, and so it is here, so all validation
// constraints will continue to work fine.
'image_upload' => $text_editor->toArray()['image_upload'],
]);
$violations = $typed_config->validate();
// Only consider validation constraint violations covering the pair, so not
// irrelevant details such as a PrimitiveTypeConstraint in filter settings,
// which do not affect CKEditor 5 anyway.
foreach ($violations as $i => $violation) {
assert($violation instanceof ConstraintViolation);
if (explode('.', $violation->getPropertyPath())[0] === 'filters' && is_a($violation->getConstraint(), PrimitiveTypeConstraint::class)) {
$violations->remove($i);
}
}
if (!$all_compatibility_problems) {
foreach ($violations as $i => $violation) {
// Remove all violations that are not fundamental — these are at the
// root (property path '').
if ($violation->getPropertyPath() !== '') {
$violations->remove($i);
}
}
}
return $violations;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.