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