I have a custom entity with an integer field with the following baseFieldDefinition:
$fields['permission_level'] = BaseFieldDefinition::create('integer') ->setLabel(t("Permission Level")) ->setDescription(t("Sets amount of permissions owner has")) ->addConstraint('Range', ['min' => 0]) ->setDefaultValue(0) ->setDisplayOptions('form', [ 'type' => 'number' ]);
because of the
->addConstraint('Range', ['min' => 0]), drupal throws an error anytime I try to create an entity through either the
drupal generate:entity:content generated boilerplate form or json:api post requests.
I have used Xdebug to narrow the issue to the constraint validator range. Something is passing a FieldListItem object instead of an integer to this constraint validator causing it to fail because its not an integer. The weird thing is that inside the FieldListItem object is the integer I input.
Why is drupal passing a FieldListItem object instead of an Integer?