‪TYPO3CMS  ‪main
SlugEnricher.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 
21 
33 {
37  protected ‪$slugFieldNamesPerTable = [];
38 
39  public function ‪__construct()
40  {
41  trigger_error('Class ' . __CLASS__ . ' will be removed with TYPO3 v14.0.', E_USER_DEPRECATED);
42  }
43 
44  public function ‪enrichDataMap(array $dataMap): array
45  {
46  foreach ($dataMap as $tableName => &$tableDataMap) {
47  $slugFieldNames = $this->‪resolveSlugFieldNames($tableName);
48  if (empty($slugFieldNames)) {
49  continue;
50  }
51  foreach ($tableDataMap as ‪$identifier => &$fieldValues) {
53  continue;
54  }
55  $fieldValues = $this->‪enrichUndefinedSlugFieldNames(
56  $slugFieldNames,
57  $fieldValues
58  );
59  }
60  }
61  return $dataMap;
62  }
63 
64  protected function ‪enrichUndefinedSlugFieldNames(array $slugFieldNames, array $fieldValues): array
65  {
66  if (empty($slugFieldNames)) {
67  return [];
68  }
69  $undefinedSlugFieldNames = array_diff(
70  $slugFieldNames,
71  array_keys($fieldValues)
72  );
73  if (empty($undefinedSlugFieldNames)) {
74  return $fieldValues;
75  }
76  return array_merge(
77  $fieldValues,
78  array_fill_keys(
79  $undefinedSlugFieldNames,
80  ''
81  )
82  );
83  }
84 
88  public function ‪resolveSlugFieldNames(string $tableName): array
89  {
90  if (isset($this->slugFieldNamesPerTable[$tableName])) {
91  return $this->slugFieldNamesPerTable[$tableName];
92  }
93 
94  return $this->slugFieldNamesPerTable[$tableName] = array_keys(
95  array_filter(
96  ‪$GLOBALS['TCA'][$tableName]['columns'] ?? [],
97  static function (array $settings): bool {
98  return ($settings['config']['type'] ?? null) === 'slug';
99  }
100  )
101  );
102  }
103 }
‪TYPO3\CMS\Core\DataHandling\SlugEnricher\enrichDataMap
‪enrichDataMap(array $dataMap)
Definition: SlugEnricher.php:43
‪TYPO3\CMS\Core\DataHandling\SlugEnricher
Definition: SlugEnricher.php:33
‪TYPO3\CMS\Core\DataHandling\SlugEnricher\$slugFieldNamesPerTable
‪array $slugFieldNamesPerTable
Definition: SlugEnricher.php:36
‪TYPO3\CMS\Core\DataHandling
Definition: DataHandler.php:16
‪TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger
‪static bool canBeInterpretedAsInteger(mixed $var)
Definition: MathUtility.php:69
‪TYPO3\CMS\Core\DataHandling\SlugEnricher\__construct
‪__construct()
Definition: SlugEnricher.php:38
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:24
‪TYPO3\CMS\Core\DataHandling\SlugEnricher\enrichUndefinedSlugFieldNames
‪enrichUndefinedSlugFieldNames(array $slugFieldNames, array $fieldValues)
Definition: SlugEnricher.php:63
‪TYPO3\CMS\Webhooks\Message\$identifier
‪identifier readonly string $identifier
Definition: FileAddedMessage.php:37
‪TYPO3\CMS\Core\DataHandling\SlugEnricher\resolveSlugFieldNames
‪string[] resolveSlugFieldNames(string $tableName)
Definition: SlugEnricher.php:87