‪TYPO3CMS  9.5
PlaceholderShadowColumnsResolver.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
21 
34 {
35  protected const ‪CONTROL_COLUMNS = [
36  'languageField',
37  'transOrigPointerField',
38  'translationSource',
39  'type',
40  'label'
41  ];
42 
43  protected const ‪FLAG_NONE = 0;
44  protected const ‪FLAG_APPLY_SYSTEM_COLUMNS = 1;
45  protected const ‪FLAG_APPLY_SLUG_COLUMNS = 2;
46 
50  protected ‪$tableName;
51 
55  protected ‪$tableConfiguration;
56 
60  protected ‪$flags;
61 
67  public function ‪__construct(string ‪$tableName, array ‪$tableConfiguration)
68  {
69  $this->tableName = ‪$tableName;
70  $this->tableConfiguration = ‪$tableConfiguration;
71 
72  if (empty($this->tableName) || empty($this->tableConfiguration)) {
73  throw new ‪Exception('No table name and TCA given', 1574174231);
74  }
75  }
76 
81  public function ‪forNewPlaceholder(int ‪$flags = null): array
82  {
83  ‪$flags = ‪$flags ?? self::FLAG_APPLY_SYSTEM_COLUMNS | ‪self::FLAG_APPLY_SLUG_COLUMNS;
84  $shadowColumnsList = $this->tableConfiguration['ctrl']['shadowColumnsForNewPlaceholders'] ?? '';
85  return $this->‪forTable($shadowColumnsList, ‪$flags);
86  }
87 
92  public function ‪forMovePlaceholder(int ‪$flags = null): array
93  {
94  $shadowColumnsList = $this->tableConfiguration['ctrl']['shadowColumnsForMovePlaceholders']
95  ?? $this->tableConfiguration['ctrl']['shadowColumnsForNewPlaceholders'] ?? '';
96  // @todo Applying same flags as for new-placeholders would streamline database integrity
97  return $this->‪forTable($shadowColumnsList, ‪$flags);
98  }
99 
100  protected function ‪forTable(string $shadowColumnsList, int ‪$flags = null): array
101  {
102  $shadowColumns = explode(',', $shadowColumnsList);
104 
105  if (‪$flags & self::FLAG_APPLY_SYSTEM_COLUMNS) {
106  foreach (self::CONTROL_COLUMNS as $controlColumn) {
107  if (isset($this->tableConfiguration['ctrl'][$controlColumn])) {
108  $shadowColumns[] = $this->tableConfiguration['ctrl'][$controlColumn];
109  }
110  }
111  }
112  if (‪$flags & self::FLAG_APPLY_SLUG_COLUMNS) {
113  $shadowColumns = array_merge(
114  $shadowColumns,
115  GeneralUtility::makeInstance(SlugEnricher::class)->resolveSlugFieldNames($this->tableName)
116  );
117  }
118  foreach ($this->tableConfiguration['ctrl']['enablecolumns'] ?? [] as $enableColumn) {
119  $shadowColumns[] = $enableColumn;
120  }
121 
122  $shadowColumns = array_filter(
123  array_map('trim', $shadowColumns),
124  function (string $shadowColumn) {
125  return !empty($shadowColumn) && $shadowColumn !== 'uid' && $shadowColumn !== 'pid'
126  && isset($this->tableConfiguration['columns'][$shadowColumn]);
127  }
128  );
129  $shadowColumns = array_unique($shadowColumns);
130  return $shadowColumns;
131  }
132 }
‪TYPO3\CMS\Core\DataHandling\PlaceholderShadowColumnsResolver\forTable
‪forTable(string $shadowColumnsList, int $flags=null)
Definition: PlaceholderShadowColumnsResolver.php:97
‪TYPO3\CMS\Core\DataHandling\PlaceholderShadowColumnsResolver\FLAG_APPLY_SLUG_COLUMNS
‪const FLAG_APPLY_SLUG_COLUMNS
Definition: PlaceholderShadowColumnsResolver.php:45
‪TYPO3\CMS\Core\Exception
Definition: Exception.php:21
‪TYPO3\CMS\Core\DataHandling\PlaceholderShadowColumnsResolver\forNewPlaceholder
‪string[] forNewPlaceholder(int $flags=null)
Definition: PlaceholderShadowColumnsResolver.php:78
‪TYPO3\CMS\Core\DataHandling\PlaceholderShadowColumnsResolver\$tableConfiguration
‪array $tableConfiguration
Definition: PlaceholderShadowColumnsResolver.php:53
‪TYPO3\CMS\Core\DataHandling
Definition: DataHandler.php:2
‪TYPO3\CMS\Core\Exception
‪TYPO3\CMS\Core\DataHandling\PlaceholderShadowColumnsResolver\FLAG_NONE
‪const FLAG_NONE
Definition: PlaceholderShadowColumnsResolver.php:43
‪TYPO3\CMS\Core\DataHandling\PlaceholderShadowColumnsResolver
Definition: PlaceholderShadowColumnsResolver.php:34
‪TYPO3\CMS\Core\DataHandling\PlaceholderShadowColumnsResolver\forMovePlaceholder
‪string[] forMovePlaceholder(int $flags=null)
Definition: PlaceholderShadowColumnsResolver.php:89
‪TYPO3\CMS\Core\DataHandling\PlaceholderShadowColumnsResolver\__construct
‪__construct(string $tableName, array $tableConfiguration)
Definition: PlaceholderShadowColumnsResolver.php:64
‪TYPO3\CMS\Core\DataHandling\PlaceholderShadowColumnsResolver\CONTROL_COLUMNS
‪const CONTROL_COLUMNS
Definition: PlaceholderShadowColumnsResolver.php:35
‪TYPO3\CMS\Core\DataHandling\PlaceholderShadowColumnsResolver\$flags
‪int null $flags
Definition: PlaceholderShadowColumnsResolver.php:57
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\DataHandling\PlaceholderShadowColumnsResolver\FLAG_APPLY_SYSTEM_COLUMNS
‪const FLAG_APPLY_SYSTEM_COLUMNS
Definition: PlaceholderShadowColumnsResolver.php:44
‪TYPO3\CMS\Core\DataHandling\PlaceholderShadowColumnsResolver\$tableName
‪string $tableName
Definition: PlaceholderShadowColumnsResolver.php:49