protected function YamlFormEntityElementsValidator::validateRendering in YAML Form 8
Validate that elements are a valid render array.
Return value
\Drupal\Core\StringTranslation\TranslatableMarkup|string|null If not valid an error message.
See also
\Drupal\Core\Entity\EntityFormBuilder
\Drupal\yamlform\Entity\YamlForm::getSubmissionForm()
1 call to YamlFormEntityElementsValidator::validateRendering()
- YamlFormEntityElementsValidator::validate in src/
YamlFormEntityElementsValidator.php - Validate form elements.
File
- src/
YamlFormEntityElementsValidator.php, line 337
Class
- YamlFormEntityElementsValidator
- Defines a class to validate form elements.
Namespace
Drupal\yamlformCode
protected function validateRendering() {
set_error_handler('_yamlform_entity_element_validate_rendering_error_handler');
try {
/** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
$entity_type_manager = \Drupal::service('entity_type.manager');
/** @var \Drupal\Core\Form\FormBuilderInterface $form_builder */
$form_builder = \Drupal::service('form_builder');
/** @var \Drupal\yamlform\YamlFormSubmissionInterface $yamlform_submission */
$yamlform_submission = $entity_type_manager
->getStorage('yamlform_submission')
->create([
'yamlform' => $this->yamlform,
]);
$form_object = $entity_type_manager
->getFormObject('yamlform_submission', 'default');
$form_object
->setEntity($yamlform_submission);
$form_state = (new FormState())
->setFormState([]);
$form_builder
->buildForm($form_object, $form_state);
$message = NULL;
} catch (\Exception $exception) {
$message = $exception
->getMessage();
}
set_error_handler('_drupal_error_handler');
if ($message) {
$build = [
'title' => [
'#markup' => $this
->t('Unable to render elements, please view the below message(s) and the error log.'),
],
'items' => [
'#theme' => 'item_list',
'#items' => [
$message,
],
],
];
return \Drupal::service('renderer')
->renderPlain($build);
}
return $message;
}