‪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 
32 {
36  protected ‪$slugFieldNamesPerTable = [];
37 
38  public function ‪enrichDataMap(array $dataMap): array
39  {
40  foreach ($dataMap as $tableName => &$tableDataMap) {
41  $slugFieldNames = $this->‪resolveSlugFieldNames($tableName);
42  if (empty($slugFieldNames)) {
43  continue;
44  }
45  foreach ($tableDataMap as ‪$identifier => &$fieldValues) {
47  continue;
48  }
49  $fieldValues = $this->‪enrichUndefinedSlugFieldNames(
50  $slugFieldNames,
51  $fieldValues
52  );
53  }
54  }
55  return $dataMap;
56  }
57 
58  protected function ‪enrichUndefinedSlugFieldNames(array $slugFieldNames, array $fieldValues): array
59  {
60  if (empty($slugFieldNames)) {
61  return [];
62  }
63  $undefinedSlugFieldNames = array_diff(
64  $slugFieldNames,
65  array_keys($fieldValues)
66  );
67  if (empty($undefinedSlugFieldNames)) {
68  return $fieldValues;
69  }
70  return array_merge(
71  $fieldValues,
72  array_fill_keys(
73  $undefinedSlugFieldNames,
74  ''
75  )
76  );
77  }
78 
82  public function ‪resolveSlugFieldNames(string $tableName): array
83  {
84  if (isset($this->slugFieldNamesPerTable[$tableName])) {
85  return $this->slugFieldNamesPerTable[$tableName];
86  }
87 
88  return $this->slugFieldNamesPerTable[$tableName] = array_keys(
89  array_filter(
90  ‪$GLOBALS['TCA'][$tableName]['columns'] ?? [],
91  static function (array $settings) {
92  return ($settings['config']['type'] ?? null) === 'slug';
93  }
94  )
95  );
96  }
97 }
‪TYPO3\CMS\Core\DataHandling\SlugEnricher\enrichDataMap
‪enrichDataMap(array $dataMap)
Definition: SlugEnricher.php:37
‪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\Utility\MathUtility\canBeInterpretedAsInteger
‪static bool canBeInterpretedAsInteger(mixed $var)
Definition: MathUtility.php:69
‪$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:57
‪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:81