Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CreateEntityRow.php
Go to the documentation of this file.
1 <?php
7 
10 
15 {
19  protected $metadataPool;
20 
24  public function __construct(
26  ) {
27  $this->metadataPool = $metadataPool;
28  }
29 
35  protected function prepareData(EntityMetadata $metadata, $data)
36  {
37  $output = [];
38  foreach ($metadata->getEntityConnection()->describeTable($metadata->getEntityTable()) as $column) {
39  if ($column['DEFAULT'] == 'CURRENT_TIMESTAMP' /*|| $column['IDENTITY']*/) {
40  continue;
41  }
42  if (isset($data[strtolower($column['COLUMN_NAME'])])) {
43  $output[strtolower($column['COLUMN_NAME'])] = $data[strtolower($column['COLUMN_NAME'])];
44  } elseif ($column['DEFAULT'] === null) {
45  $output[strtolower($column['COLUMN_NAME'])] = null;
46  }
47  }
48  if (empty($data[$metadata->getIdentifierField()])) {
49  $output[$metadata->getIdentifierField()] = $metadata->generateIdentifier();
50  }
51  return $output;
52  }
53 
59  public function execute($entityType, $data)
60  {
61  $metadata = $this->metadataPool->getMetadata($entityType);
62 
63  $linkField = $metadata->getLinkField();
64  $entityTable = $metadata->getEntityTable();
65  $connection = $metadata->getEntityConnection();
66 
67  $connection->insert($entityTable, $this->prepareData($metadata, $data));
68 
69  $data[$linkField] = $connection->lastInsertId($entityTable);
70 
71  return $data;
72  }
73 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$connection
Definition: bulk.php:13
$entityTable
Definition: tablerates.php:11