Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TypeFactory.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
13 
18 {
22  private $objectManager;
23 
27  private $argumentFactory;
28 
32  private $fieldFactory;
33 
39  public function __construct(
40  ObjectManagerInterface $objectManager,
41  ArgumentFactory $argumentFactory,
42  FieldFactory $fieldFactory
43  ) {
44  $this->objectManager = $objectManager;
45  $this->argumentFactory = $argumentFactory;
46  $this->fieldFactory = $fieldFactory;
47  }
48 
56  {
57  $fields = [];
58  $data['fields'] = isset($data['fields']) ? $data['fields'] : [];
59  foreach ($data['fields'] as $field) {
60  $arguments = [];
61  foreach ($field['arguments'] as $argument) {
62  $arguments[$argument['name']] = $this->argumentFactory->createFromConfigData($argument);
63  }
64  $fields[$field['name']] = $this->fieldFactory->createFromConfigData(
65  $field,
67  );
68  }
69  return $this->create(
70  $data,
71  $fields
72  );
73  }
74 
85  public function create(
86  array $typeData,
87  array $fields
88  ) : Type {
89  return $this->objectManager->create(
90  Type::class,
91  [
92  'name' => $typeData['name'],
93  'fields' => $fields,
94  'interfaces' => isset($typeData['implements']) ? $typeData['implements'] : [],
95  'description' => isset($typeData['description']) ? $typeData['description'] : ''
96  ]
97  );
98  }
99 }
$objectManager
Definition: bootstrap.php:17
$fields
Definition: details.phtml:14
$arguments
__construct(ObjectManagerInterface $objectManager, ArgumentFactory $argumentFactory, FieldFactory $fieldFactory)
Definition: TypeFactory.php:39