protected static function WebformCodeMirror::validateHtml in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Element/WebformCodeMirror.php \Drupal\webform\Element\WebformCodeMirror::validateHtml()
Validate HTML.
Parameters
array $element: The form element whose value is being validated.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
array $complete_form: The complete form structure.
Return value
array|null An array of error messages.
1 call to WebformCodeMirror::validateHtml()
- WebformCodeMirror::getErrors in src/
Element/ WebformCodeMirror.php - Get validation errors.
File
- src/
Element/ WebformCodeMirror.php, line 253
Class
- WebformCodeMirror
- Provides a webform element for using CodeMirror.
Namespace
Drupal\webform\ElementCode
protected static function validateHtml($element, FormStateInterface $form_state, $complete_form) {
// @see: http://stackoverflow.com/questions/3167074/which-function-in-php-validate-if-the-string-is-valid-html
// @see: http://stackoverflow.com/questions/5030392/x-html-validator-in-php
libxml_use_internal_errors(TRUE);
if (simplexml_load_string('<fragment>' . $element['#value'] . '</fragment>')) {
return NULL;
}
$errors = libxml_get_errors();
libxml_clear_errors();
if (!$errors) {
return NULL;
}
$messages = [];
foreach ($errors as $error) {
$messages[] = $error->message;
}
return $messages;
}