Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CustomAttributeMetadata.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
18 
23 {
27  private $type;
28 
32  public function __construct(Type $type)
33  {
34  $this->type = $type;
35  }
36 
40  public function resolve(
41  Field $field,
42  $context,
44  array $value = null,
45  array $args = null
46  ) {
47  $attributes['items'] = null;
48  $attributeInputs = $args['attributes'];
49  foreach ($attributeInputs as $attribute) {
50  if (!isset($attribute['attribute_code']) || !isset($attribute['entity_type'])) {
51  $attributes['items'][] = $this->createInputException($attribute);
52  continue;
53  }
54  try {
55  $type = $this->type->getType($attribute['attribute_code'], $attribute['entity_type']);
56  } catch (InputException $exception) {
58  __(
59  'Attribute code %1 of entity type %2 not configured to have a type.',
60  [$attribute['attribute_code'], $attribute['entity_type']]
61  )
62  );
63  continue;
64  } catch (LocalizedException $exception) {
65  $attributes['items'][] = new GraphQlInputException(
66  __(
67  'Invalid entity_type specified: %1',
68  [$attribute['entity_type']]
69  )
70  );
71  continue;
72  }
73 
74  if (empty($type)) {
75  continue;
76  }
77 
78  $attributes['items'][] = [
79  'attribute_code' => $attribute['attribute_code'],
80  'entity_type' => $attribute['entity_type'],
81  'attribute_type' => ucfirst($type)
82  ];
83  }
84 
85  return $attributes;
86  }
87 
94  private function createInputException(array $attribute) : GraphQlInputException
95  {
96  $isCodeSet = isset($attribute['attribute_code']);
97  $isEntitySet = isset($attribute['entity_type']);
98  $messagePart = !$isCodeSet ? 'attribute_code' : 'entity_type';
99  $messagePart .= !$isCodeSet && !$isEntitySet ? '/entity_type' : '';
100  $identifier = "Empty AttributeInput";
101  if ($isCodeSet) {
102  $identifier = 'attribute_code: ' . $attribute['attribute_code'];
103  } elseif ($isEntitySet) {
104  $identifier = 'entity_type: ' . $attribute['entity_type'];
105  }
106 
107  return new GraphQlInputException(
108  __(
109  'Missing %1 for the input %2.',
110  [$messagePart, $identifier]
111  )
112  );
113  }
114 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__()
Definition: __.php:13
$type
Definition: item.phtml:13
$value
Definition: gender.phtml:16
resolve(Field $field, $context, ResolveInfo $info, array $value=null, array $args=null)
$attributes
Definition: matrix.phtml:13
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52