‪TYPO3CMS  ‪main
TypeInlineExpandsingle.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  // matches only field inline_1 of tx_styleguide_inline_expandsingle
42  'foreign_table' => 'tx_styleguide_inline_expandsingle_child',
43  'foreign_field' => 'parentid',
44  'foreign_table_field' => 'parenttable',
45  ],
46  ],
47  ];
48 
55  public function ‪match(array $data): bool
56  {
57  return $this->‪checkMatchArray($data, $this->matchArray);
58  }
59 
66  public function ‪generate(array $data): string
67  {
68  $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
69  $connection = $connectionPool->getConnectionForTable('tx_styleguide_inline_expandsingle_child');
70  $childRowsToCreate = 3;
71  for ($i = 0; $i < $childRowsToCreate; $i++) {
72  // Insert an empty row again to have the uid already. This is useful for
73  // possible further inline that may be attached to this child.
74  $childFieldValues = [
75  'pid' => $data['fieldValues']['pid'],
76  'parentid' => $data['fieldValues']['uid'],
77  'parenttable' => $data['tableName'],
78  ];
79  $connection->insert(
80  'tx_styleguide_inline_expandsingle_child',
81  $childFieldValues
82  );
83  $childFieldValues['uid'] = $connection->lastInsertId();
84  $recordData = GeneralUtility::makeInstance(RecordData::class);
85  $childFieldValues = $recordData->generate('tx_styleguide_inline_expandsingle_child', $childFieldValues);
86  $connection->update(
87  'tx_styleguide_inline_expandsingle_child',
88  $childFieldValues,
89  [ 'uid' => $childFieldValues['uid'] ]
90  );
91  }
92  return (string)$childRowsToCreate;
93  }
94 }
‪TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator\TypeInlineExpandsingle
Definition: TypeInlineExpandsingle.php:33
‪TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator\AbstractFieldGenerator
Definition: AbstractFieldGenerator.php:29
‪TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator\AbstractFieldGenerator\checkMatchArray
‪bool checkMatchArray(array $data, array $matchArray)
Definition: AbstractFieldGenerator.php:65
‪TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator\TypeInlineExpandsingle\match
‪bool match(array $data)
Definition: TypeInlineExpandsingle.php:54
‪TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator
Definition: AbstractFieldGenerator.php:18
‪TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator\TypeInlineExpandsingle\$matchArray
‪array $matchArray
Definition: TypeInlineExpandsingle.php:36
‪TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator\TypeInlineExpandsingle\generate
‪string generate(array $data)
Definition: TypeInlineExpandsingle.php:65
‪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\RecordData
Definition: RecordData.php:28