mirror of
https://github.com/farmOS/farmOS.git
synced 2024-02-23 11:37:38 +01:00
Validate quantity entities created by create_quantity #721
This commit is contained in:
parent
5ba9baee5d
commit
109faec636
2 changed files with 15 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in a new issue