Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Drupal/FormGeneratorDrupal.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function doTransform($data, Context $context = NULL) {
*/
public function getInputValidator() {
// Validate the JSON-Schema input.
return new JsonSchemaFormValidator(new Validator());
return new JsonSchemaFormValidator(new Validator(), Constraint::CHECK_MODE_TYPE_CAST);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/Drupal/FormValidatorDrupal.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use JsonSchema\Constraints\Constraint;
use JsonSchema\Validator;
use SchemaForms\ArrayToStdClass;
use SchemaForms\RecursiveTypeCaster;
Expand Down Expand Up @@ -38,7 +39,10 @@ public static function validateWithSchema(array &$element, FormStateInterface $f
}
$validator = new Validator();
// Validate the massaged data against the schema.
$num_errors = $validator->validate($data, $schema);
if ($data === null) {
$data = [];
}
$num_errors = $validator->validate($data, $schema, Constraint::CHECK_MODE_TYPE_CAST);
if ($num_errors) {
// Build the mappings of paths to form paths.
$mappings = static::buildMappingsElementPaths($element, $element['#array_parents']);
Expand Down
3 changes: 1 addition & 2 deletions src/JsonSchemaFormValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ public function __construct(Validator $validator, $mode = NULL) {
*/
public function isValid($data) {
return parent::isValid($data)
&& $data->type === 'object'
&& (bool) $data->properties;
&& $data->type === 'object';
}

}