‪TYPO3CMS  ‪main
TypeInlineUsecombinationGroup.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' => 'group_parent',
43  'foreign_selector' => 'group_child',
44  'foreign_unique' => 'group_child',
45  ],
46  ],
47  ];
48 
55  public function ‪match(array $data): bool
56  {
57  $match = parent::match($data);
58  if ($match && $data['fieldConfig']['config']['foreign_table'] !== 'tx_styleguide_inline_usecombinationgroup_mm') {
59  $match = false;
60  }
61  return $match;
62  }
63 
70  public function ‪generate(array $data): string
71  {
72  if (!isset(‪$GLOBALS['TCA'][$data['fieldConfig']['config']['foreign_table']]['columns']['group_child']['config']['allowed'])) {
73  throw new \RuntimeException(
74  'mm child table name not found',
75  1706633899
76  );
77  }
78  $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
79  $childChildTableName = ‪$GLOBALS['TCA'][$data['fieldConfig']['config']['foreign_table']]['columns']['group_child']['config']['allowed'];
80  $numberOfChildChildRowsToCreate = 4;
81  $uidsOfChildrenToConnect = [];
82  for ($i = 0; $i < $numberOfChildChildRowsToCreate; $i++) {
83  // Insert an empty row again to have the uid already. This is useful for
84  // possible further inline that may be attached to this child.
85  $childFieldValues = [
86  'pid' => $data['fieldValues']['pid'],
87  ];
88  $connection = $connectionPool->getConnectionForTable($childChildTableName);
89  $connection->insert($childChildTableName, $childFieldValues);
90  $childFieldValues['uid'] = $connection->lastInsertId();
91  if (count($uidsOfChildrenToConnect) < 2) {
92  $uidsOfChildrenToConnect[] = $childFieldValues['uid'];
93  }
94  $recordData = GeneralUtility::makeInstance(RecordData::class);
95  $childFieldValues = $recordData->generate($childChildTableName, $childFieldValues);
96  $connection->update(
97  $childChildTableName,
98  $childFieldValues,
99  [ 'uid' => (int)$childFieldValues['uid'] ]
100  );
101  }
102  foreach ($uidsOfChildrenToConnect as ‪$uid) {
103  $mmFieldValues = [
104  'pid' => $data['fieldValues']['pid'],
105  'group_parent' => $data['fieldValues']['uid'],
106  'group_child' => ‪$uid,
107  ];
108  $tableName = $data['fieldConfig']['config']['foreign_table'];
109  $connection = $connectionPool->getConnectionForTable($tableName);
110  $connection->insert($tableName, $mmFieldValues);
111  }
112  return (string)count($uidsOfChildrenToConnect);
113  }
114 }
‪TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator\AbstractFieldGenerator
Definition: AbstractFieldGenerator.php:29
‪TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator\TypeInlineUsecombinationGroup\$matchArray
‪array $matchArray
Definition: TypeInlineUsecombinationGroup.php:36
‪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\Styleguide\TcaDataGenerator\FieldGenerator\TypeInlineUsecombinationGroup\match
‪bool match(array $data)
Definition: TypeInlineUsecombinationGroup.php:54
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator\TypeInlineUsecombinationGroup
Definition: TypeInlineUsecombinationGroup.php:33
‪TYPO3\CMS\Styleguide\TcaDataGenerator\RecordData
Definition: RecordData.php:28
‪TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator\TypeInlineUsecombinationGroup\generate
‪string generate(array $data)
Definition: TypeInlineUsecombinationGroup.php:69