‪TYPO3CMS  ‪main
TcaUuid.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 
20 use Symfony\Component\Uid\Uuid;
22 
27 {
28  public function ‪addData(array $result): array
29  {
30  foreach ($result['processedTca']['columns'] as $fieldName => $fieldConfig) {
31  if (($fieldConfig['config']['type'] ?? '') !== 'uuid') {
32  continue;
33  }
34 
35  // Skip if field is already filled with a valid uuid
36  if (Uuid::isValid((string)($result['databaseRow'][$fieldName] ?? ''))) {
37  continue;
38  }
39 
40  $result['databaseRow'][$fieldName] = (string)match ((int)($fieldConfig['config']['version'] ?? 0)) {
41  6 => Uuid::v6(),
42  7 => Uuid::v7(),
43  default => Uuid::v4()
44  };
45  }
46 
47  return $result;
48  }
49 }
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaUuid\addData
‪addData(array $result)
Definition: TcaUuid.php:28
‪TYPO3\CMS\Backend\Form\FormDataProvider
Definition: AbstractDatabaseRecordProvider.php:16
‪TYPO3\CMS\Backend\Form\FormDataProviderInterface
Definition: FormDataProviderInterface.php:23
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaUuid
Definition: TcaUuid.php:27