diff --git a/CHANGELOG.md b/CHANGELOG.md index c4b8455b..a3c15420 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [Misc quick form code and documentation improvements #703](https://github.com/farmOS/farmOS/pull/703) +### Fixed + +- [Validate quantity entities created by create_quantity #721](https://github.com/farmOS/farmOS/pull/721) + ## [2.1.3] 2023-09-20 ### Changed diff --git a/modules/core/quantity/src/Plugin/migrate/process/CreateQuantity.php b/modules/core/quantity/src/Plugin/migrate/process/CreateQuantity.php index 4d904507..5dabe7b2 100644 --- a/modules/core/quantity/src/Plugin/migrate/process/CreateQuantity.php +++ b/modules/core/quantity/src/Plugin/migrate/process/CreateQuantity.php @@ -5,6 +5,7 @@ namespace Drupal\quantity\Plugin\migrate\process; use Drupal\Component\Utility\NestedArray; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\migrate\MigrateExecutableInterface; +use Drupal\migrate\MigrateSkipRowException; use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\Row; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -74,8 +75,18 @@ class CreateQuantity extends ProcessPluginBase implements ContainerFactoryPlugin } // Create the entity. + /** @var \Drupal\quantity\Entity\QuantityInterface $entity */ $entity = $this->quantityStorage->create($entity_values); + // Validate the entity. + /** @var \Symfony\Component\Validator\ConstraintViolationInterface[] $violations */ + $violations = $entity->validate(); + if (!empty($violations)) { + foreach ($violations as $violation) { + throw new MigrateSkipRowException($violation->getPropertyPath() . '=' . $violation->getMessage()); + } + } + // Save the entity so it has an ID. $entity->save();