EntityCrudOutputViolations::resolveValues()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 4
nc 4
nop 4
1
<?php
2
3
namespace Drupal\graphql_core\Plugin\GraphQL\Fields\Mutations;
4
5
use Drupal\graphql\GraphQL\Execution\ResolveContext;
6
use Drupal\graphql_core\GraphQL\EntityCrudOutputWrapper;
7
use Drupal\graphql\Plugin\GraphQL\Fields\FieldPluginBase;
8
use GraphQL\Type\Definition\ResolveInfo;
9
10
/**
11
 * Retrieve a list of entity mutation constraint violations.
12
 *
13
 * @GraphQLField(
14
 *   id = "entity_crud_output_violations",
15
 *   secure = true,
16
 *   name = "violations",
17
 *   type = "[ConstraintViolation]",
18
 *   parents = {"EntityCrudOutput"}
19
 * )
20
 */
21
class EntityCrudOutputViolations extends FieldPluginBase {
22
23
  /**
24
   * {@inheritdoc}
25
   */
26
  public function resolveValues($value, array $args, ResolveContext $context, ResolveInfo $info) {
27
    if ($value instanceof EntityCrudOutputWrapper) {
28
      if ($violations = $value->getViolations()) {
29
        foreach ($violations as $violation) {
30
          yield $violation;
31
        }
32
      }
33
    }
34
  }
35
36
}
37