‪TYPO3CMS  ‪main
TypeInline1n.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 
31 {
35  protected ‪$matchArray = [
36  'fieldConfig' => [
37  'config' => [
38  'type' => 'inline',
39  'foreign_field' => 'parentid',
40  'foreign_table_field' => 'parenttable',
41  ],
42  ],
43  ];
44 
51  public function ‪match(array $data): bool
52  {
53  $result = $this->‪checkMatchArray($data, $this->matchArray);
54  if ($result && isset($data['fieldConfig']['config']['foreign_table'])) {
55  $result = true;
56  } else {
57  $result = false;
58  }
59  return $result;
60  }
61 
68  public function ‪generate(array $data): string
69  {
70  $childTable = $data['fieldConfig']['config']['foreign_table'];
71  // Insert an empty row again to have the uid already. This is useful for
72  // possible further inline that may be attached to this child.
73  $childFieldValues = [
74  'pid' => $data['fieldValues']['pid'],
75  'parentid' => $data['fieldValues']['uid'],
76  'parenttable' => $data['tableName'],
77  ];
78  if ($data['fieldConfig']['config']['foreign_match_fields']['role'] ?? false) {
79  $childFieldValues['role'] = $data['fieldConfig']['config']['foreign_match_fields']['role'];
80  }
81  $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($childTable);
82  $connection->insert($childTable, $childFieldValues);
83  $childFieldValues['uid'] = (int)$connection->lastInsertId();
84  $recordData = GeneralUtility::makeInstance(RecordData::class);
85  $childFieldValues = $recordData->generate($childTable, $childFieldValues);
86  $connection->update(
87  $childTable,
88  $childFieldValues,
89  [ 'uid' => $childFieldValues['uid'] ]
90  );
91  return (string)1;
92  }
93 }
‪TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator\TypeInline1n\$matchArray
‪array $matchArray
Definition: TypeInline1n.php:34
‪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
Definition: AbstractFieldGenerator.php:18
‪TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator\TypeInline1n
Definition: TypeInline1n.php:31
‪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
‪TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator\TypeInline1n\generate
‪string generate(array $data)
Definition: TypeInline1n.php:67
‪TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator\TypeInline1n\match
‪bool match(array $data)
Definition: TypeInline1n.php:50