‪TYPO3CMS  10.4
PlaceholderShadowColumnsResolver.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 
22 
35 {
36  protected const ‪CONTROL_COLUMNS = [
37  'languageField',
38  'transOrigPointerField',
39  'translationSource',
40  'type',
41  'label'
42  ];
43 
44  protected const ‪FLAG_NONE = 0;
45  protected const ‪FLAG_APPLY_SYSTEM_COLUMNS = 1;
46  protected const ‪FLAG_APPLY_SLUG_COLUMNS = 2;
47 
51  protected ‪$tableName;
52 
56  protected ‪$tableConfiguration;
57 
61  protected ‪$flags;
62 
68  public function ‪__construct(string ‪$tableName, array ‪$tableConfiguration)
69  {
70  $this->tableName = ‪$tableName;
71  $this->tableConfiguration = ‪$tableConfiguration;
72 
73  if (empty($this->tableName) || empty($this->tableConfiguration)) {
74  throw new ‪Exception('No table name and TCA given', 1574174231);
75  }
76  }
77 
82  public function ‪forNewPlaceholder(int ‪$flags = null): array
83  {
84  ‪$flags = ‪$flags ?? self::FLAG_APPLY_SYSTEM_COLUMNS | ‪self::FLAG_APPLY_SLUG_COLUMNS;
85  $shadowColumnsList = $this->tableConfiguration['ctrl']['shadowColumnsForNewPlaceholders'] ?? '';
86  return $this->‪forTable($shadowColumnsList, ‪$flags);
87  }
88 
93  public function ‪forMovePlaceholder(int ‪$flags = null): array
94  {
95  $shadowColumnsList = $this->tableConfiguration['ctrl']['shadowColumnsForMovePlaceholders']
96  ?? $this->tableConfiguration['ctrl']['shadowColumnsForNewPlaceholders'] ?? '';
97  // @todo Applying same flags as for new-placeholders would streamline database integrity
98  return $this->‪forTable($shadowColumnsList, ‪$flags);
99  }
100 
101  protected function ‪forTable(string $shadowColumnsList, int ‪$flags = null): array
102  {
103  $shadowColumns = explode(',', $shadowColumnsList);
105 
106  if (‪$flags & self::FLAG_APPLY_SYSTEM_COLUMNS) {
107  foreach (self::CONTROL_COLUMNS as $controlColumn) {
108  if (isset($this->tableConfiguration['ctrl'][$controlColumn])) {
109  $shadowColumns[] = $this->tableConfiguration['ctrl'][$controlColumn];
110  }
111  }
112  }
113  if (‪$flags & self::FLAG_APPLY_SLUG_COLUMNS) {
114  $shadowColumns = array_merge(
115  $shadowColumns,
116  GeneralUtility::makeInstance(SlugEnricher::class)->resolveSlugFieldNames($this->tableName)
117  );
118  }
119  foreach ($this->tableConfiguration['ctrl']['enablecolumns'] ?? [] as $enableColumn) {
120  $shadowColumns[] = $enableColumn;
121  }
122 
123  $shadowColumns = array_filter(
124  array_map('trim', $shadowColumns),
125  function (string $shadowColumn) {
126  return !empty($shadowColumn) && $shadowColumn !== 'uid' && $shadowColumn !== 'pid'
127  && isset($this->tableConfiguration['columns'][$shadowColumn]);
128  }
129  );
130  $shadowColumns = array_unique($shadowColumns);
131  return $shadowColumns;
132  }
133 }
‪TYPO3\CMS\Core\DataHandling\PlaceholderShadowColumnsResolver\forTable
‪forTable(string $shadowColumnsList, int $flags=null)
Definition: PlaceholderShadowColumnsResolver.php:98
‪TYPO3\CMS\Core\DataHandling\PlaceholderShadowColumnsResolver\FLAG_APPLY_SLUG_COLUMNS
‪const FLAG_APPLY_SLUG_COLUMNS
Definition: PlaceholderShadowColumnsResolver.php:46
‪TYPO3\CMS\Core\Exception
Definition: Exception.php:22
‪TYPO3\CMS\Core\DataHandling\PlaceholderShadowColumnsResolver\forNewPlaceholder
‪string[] forNewPlaceholder(int $flags=null)
Definition: PlaceholderShadowColumnsResolver.php:79
‪TYPO3\CMS\Core\DataHandling\PlaceholderShadowColumnsResolver\$tableConfiguration
‪array $tableConfiguration
Definition: PlaceholderShadowColumnsResolver.php:54
‪TYPO3\CMS\Core\DataHandling
Definition: DataHandler.php:16
‪TYPO3\CMS\Core\Exception
‪TYPO3\CMS\Core\DataHandling\PlaceholderShadowColumnsResolver\FLAG_NONE
‪const FLAG_NONE
Definition: PlaceholderShadowColumnsResolver.php:44
‪TYPO3\CMS\Core\DataHandling\PlaceholderShadowColumnsResolver
Definition: PlaceholderShadowColumnsResolver.php:35
‪TYPO3\CMS\Core\DataHandling\PlaceholderShadowColumnsResolver\forMovePlaceholder
‪string[] forMovePlaceholder(int $flags=null)
Definition: PlaceholderShadowColumnsResolver.php:90
‪TYPO3\CMS\Core\DataHandling\PlaceholderShadowColumnsResolver\__construct
‪__construct(string $tableName, array $tableConfiguration)
Definition: PlaceholderShadowColumnsResolver.php:65
‪TYPO3\CMS\Core\DataHandling\PlaceholderShadowColumnsResolver\CONTROL_COLUMNS
‪const CONTROL_COLUMNS
Definition: PlaceholderShadowColumnsResolver.php:36
‪TYPO3\CMS\Core\DataHandling\PlaceholderShadowColumnsResolver\$flags
‪int null $flags
Definition: PlaceholderShadowColumnsResolver.php:58
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\DataHandling\PlaceholderShadowColumnsResolver\FLAG_APPLY_SYSTEM_COLUMNS
‪const FLAG_APPLY_SYSTEM_COLUMNS
Definition: PlaceholderShadowColumnsResolver.php:45
‪TYPO3\CMS\Core\DataHandling\PlaceholderShadowColumnsResolver\$tableName
‪string $tableName
Definition: PlaceholderShadowColumnsResolver.php:50