‪TYPO3CMS  10.4
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 
32 {
36  protected ‪$slugFieldNamesPerTable = [];
37 
42  public function ‪enrichDataMap(array $dataMap): array
43  {
44  foreach ($dataMap as $tableName => &$tableDataMap) {
45  $slugFieldNames = $this->‪resolveSlugFieldNames($tableName);
46  if (empty($slugFieldNames)) {
47  continue;
48  }
49  foreach ($tableDataMap as $identifier => &$fieldValues) {
51  continue;
52  }
53  $fieldValues = $this->‪enrichUndefinedSlugFieldNames(
54  $slugFieldNames,
55  $fieldValues
56  );
57  }
58  }
59  return $dataMap;
60  }
61 
67  protected function ‪enrichUndefinedSlugFieldNames(array $slugFieldNames, array $fieldValues): array
68  {
69  if (empty($slugFieldNames)) {
70  return [];
71  }
72  $undefinedSlugFieldNames = array_diff(
73  $slugFieldNames,
74  array_keys($fieldValues)
75  );
76  if (empty($undefinedSlugFieldNames)) {
77  return $fieldValues;
78  }
79  return array_merge(
80  $fieldValues,
81  array_fill_keys(
82  $undefinedSlugFieldNames,
83  ''
84  )
85  );
86  }
87 
92  public function ‪resolveSlugFieldNames(string $tableName): array
93  {
94  if (isset($this->slugFieldNamesPerTable[$tableName])) {
95  return $this->slugFieldNamesPerTable[$tableName];
96  }
97 
98  return $this->slugFieldNamesPerTable[$tableName] = array_keys(
99  array_filter(
100  ‪$GLOBALS['TCA'][$tableName]['columns'] ?? [],
101  function (array $settings) {
102  return ($settings['config']['type'] ?? null) === 'slug';
103  }
104  )
105  );
106  }
107 }
‪TYPO3\CMS\Core\DataHandling\SlugEnricher\enrichDataMap
‪array enrichDataMap(array $dataMap)
Definition: SlugEnricher.php:41
‪TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger
‪static bool canBeInterpretedAsInteger($var)
Definition: MathUtility.php:74
‪TYPO3\CMS\Core\DataHandling\SlugEnricher
Definition: SlugEnricher.php:32
‪TYPO3\CMS\Core\DataHandling\SlugEnricher\$slugFieldNamesPerTable
‪array $slugFieldNamesPerTable
Definition: SlugEnricher.php:35
‪TYPO3\CMS\Core\DataHandling
Definition: DataHandler.php:16
‪TYPO3\CMS\Core\DataHandling\SlugEnricher\enrichUndefinedSlugFieldNames
‪array enrichUndefinedSlugFieldNames(array $slugFieldNames, array $fieldValues)
Definition: SlugEnricher.php:66
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:22
‪TYPO3\CMS\Core\DataHandling\SlugEnricher\resolveSlugFieldNames
‪string[] resolveSlugFieldNames(string $tableName)
Definition: SlugEnricher.php:91