Skip to content

Commit

Permalink
Optional field validation.
Browse files Browse the repository at this point in the history
  • Loading branch information
guncha25 committed Aug 3, 2020
1 parent 8205ecb commit 71a2409
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Codeception/Module/DrupalEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,18 @@ public function _failed(TestCase $test, $fail) { // @codingStandardsIgnoreLine
* Data for creating entity.
* @param string $type
* Entity type.
* @param bool $validate
* Flag to validate entity fields..
*
* @return \Drupal\Core\Entity\EntityInterface|bool
* Created entity.
*/
public function createEntity(array $values = [], $type = 'node') {
public function createEntity(array $values = [], $type = 'node', $validate = TRUE) {
try {
$entity = \Drupal::entityTypeManager()
->getStorage($type)
->create($values);
if ($entity instanceof FieldableEntityInterface) {
if ($validate && $entity instanceof FieldableEntityInterface) {
$violations = $entity->validate();
if ($violations->count() > 0) {
$message = PHP_EOL;
Expand Down

0 comments on commit 71a2409

Please sign in to comment.