‪TYPO3CMS  ‪main
TypeInlineUsecombination.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
24 
33 {
37  protected ‪$matchArray = [
38  'fieldConfig' => [
39  'config' => [
40  'type' => 'inline',
41  // additional check for foreign_table in check method
42  'foreign_field' => 'select_parent',
43  'foreign_selector' => 'select_child',
44  'foreign_unique' => 'select_child',
45  ],
46  ],
47  ];
48 
56  public function ‪match(array $data): bool
57  {
58  $match = parent::match($data);
59  if ($match) {
60  if ($data['fieldConfig']['config']['foreign_table'] !== 'tx_styleguide_inline_usecombination_mm'
61  && $data['fieldConfig']['config']['foreign_table'] !== 'tx_styleguide_inline_usecombinationbox_mm'
62  ) {
63  $match = false;
64  }
65  }
66  return $match;
67  }
68 
75  public function ‪generate(array $data): string
76  {
77  if (!isset(‪$GLOBALS['TCA'][$data['fieldConfig']['config']['foreign_table']]['columns']['select_child']['config']['foreign_table'])) {
78  throw new \RuntimeException(
79  'mm child table name not found',
80  1459941569
81  );
82  }
83  $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
84  $childChildTableName = ‪$GLOBALS['TCA'][$data['fieldConfig']['config']['foreign_table']]['columns']['select_child']['config']['foreign_table'];
85  $numberOfChildChildRowsToCreate = 4;
86  $uidsOfChildrenToConnect = [];
87  for ($i = 0; $i < $numberOfChildChildRowsToCreate; $i++) {
88  // Insert an empty row again to have the uid already. This is useful for
89  // possible further inline that may be attached to this child.
90  $childFieldValues = [
91  'pid' => $data['fieldValues']['pid'],
92  ];
93  $connection = $connectionPool->getConnectionForTable($childChildTableName);
94  $connection->insert($childChildTableName, $childFieldValues);
95  $childFieldValues['uid'] = $connection->lastInsertId();
96  if (count($uidsOfChildrenToConnect) < 2) {
97  $uidsOfChildrenToConnect[] = $childFieldValues['uid'];
98  }
99  $recordData = GeneralUtility::makeInstance(RecordData::class);
100  $childFieldValues = $recordData->generate($childChildTableName, $childFieldValues);
101  $connection->update(
102  $childChildTableName,
103  $childFieldValues,
104  [ 'uid' => (int)$childFieldValues['uid'] ]
105  );
106  }
107  foreach ($uidsOfChildrenToConnect as ‪$uid) {
108  $mmFieldValues = [
109  'pid' => $data['fieldValues']['pid'],
110  'select_parent' => $data['fieldValues']['uid'],
111  'select_child' => ‪$uid,
112  ];
113  $tableName = $data['fieldConfig']['config']['foreign_table'];
114  $connection = $connectionPool->getConnectionForTable($tableName);
115  $connection->insert($tableName, $mmFieldValues);
116  }
117  return (string)count($uidsOfChildrenToConnect);
118  }
119 }
‪TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator\TypeInlineUsecombination\$matchArray
‪array $matchArray
Definition: TypeInlineUsecombination.php:36
‪TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator\TypeInlineUsecombination\generate
‪string generate(array $data)
Definition: TypeInlineUsecombination.php:74
‪TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator\AbstractFieldGenerator
Definition: AbstractFieldGenerator.php:29
‪TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator\TypeInlineUsecombination\match
‪bool match(array $data)
Definition: TypeInlineUsecombination.php:55
‪TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator
Definition: AbstractFieldGenerator.php:18
‪TYPO3\CMS\Webhooks\Message\$uid
‪identifier readonly int $uid
Definition: PageModificationMessage.php:35
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGeneratorInterface
Definition: FieldGeneratorInterface.php:26
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator\TypeInlineUsecombination
Definition: TypeInlineUsecombination.php:33
‪TYPO3\CMS\Styleguide\TcaDataGenerator\RecordData
Definition: RecordData.php:28