From 35a7e470d581434cecd29eb184638906e91774e4 Mon Sep 17 00:00:00 2001 From: Philipp Kuhlmay <typo3@treupo.de> Date: Sat, 15 Jun 2024 13:37:58 +0200 Subject: [PATCH] [TASK] Add styleguide uuid example fields This patch provides some examples for the type=uuid in ext:styleguides 'basic' table including a generator for this type. Resolves: #104117 Related: #100171 Releases: main Change-Id: Ifbf0abe28c6730e31c922992bbeadebe587c71a6 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/84724 Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Reviewed-by: Georg Ringer <georg.ringer@gmail.com> Tested-by: Georg Ringer <georg.ringer@gmail.com> Reviewed-by: Garvin Hicking <gh@faktor-e.de> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: Garvin Hicking <gh@faktor-e.de> Tested-by: core-ci <typo3@b13.com> --- .../Classes/Service/KauderwelschService.php | 32 ++++--------- .../FieldGenerator/TypeUuid.php | 47 +++++++++++++++++++ .../FieldGeneratorResolver.php | 2 + .../TCA/tx_styleguide_elements_basic.php | 28 ++++++++++- 4 files changed, 84 insertions(+), 25 deletions(-) create mode 100644 typo3/sysext/styleguide/Classes/TcaDataGenerator/FieldGenerator/TypeUuid.php diff --git a/typo3/sysext/styleguide/Classes/Service/KauderwelschService.php b/typo3/sysext/styleguide/Classes/Service/KauderwelschService.php index a076cfa4bfe0..a4c737e0d820 100644 --- a/typo3/sysext/styleguide/Classes/Service/KauderwelschService.php +++ b/typo3/sysext/styleguide/Classes/Service/KauderwelschService.php @@ -26,8 +26,6 @@ final class KauderwelschService { /** * Lorem ipsum test with fixed length. - * - * @return string */ public function getLoremIpsum(): string { @@ -36,8 +34,6 @@ final class KauderwelschService /** * Lorem ipsum test with fixed length and HTML in it. - * - * @return string */ public function getLoremIpsumHtml(): string { @@ -46,8 +42,6 @@ final class KauderwelschService /** * Get a single word - * - * @return string */ public function getWord(): string { @@ -64,8 +58,6 @@ final class KauderwelschService /** * Get an integer - * - * @return int */ public function getInteger(): int { @@ -74,8 +66,6 @@ final class KauderwelschService /** * Timestamp of a day before 1970 - * - * @return int */ public function getDateTimestamp(): int { @@ -85,8 +75,6 @@ final class KauderwelschService /** * Timestamp of a day before 1970 with seconds - * - * @return int */ public function getDatetimeTimestamp(): int { @@ -96,8 +84,6 @@ final class KauderwelschService /** * Date before 1970 as string - * - * @return string */ public function getDateString(): string { @@ -107,8 +93,6 @@ final class KauderwelschService /** * Date before 1970 with seconds as string - * - * @return string */ public function getDatetimeString(): string { @@ -118,8 +102,6 @@ final class KauderwelschService /** * Get a float - * - * @return float */ public function getFloat(): float { @@ -128,8 +110,6 @@ final class KauderwelschService /** * Get a link - * - * @return string */ public function getLink(): string { @@ -138,18 +118,22 @@ final class KauderwelschService /** * Get a valid email - * - * @return string */ public function getEmail(): string { return 'foo@example.com'; } + /** + * Get a valid uuid v4 / v7 - both have same format + */ + public function getUuid(): string + { + return '2cc152d0-08b4-438b-92e5-4b6e8d90b465'; + } + /** * Get a color as hex string - * - * @return string */ public function getHexColor(): string { diff --git a/typo3/sysext/styleguide/Classes/TcaDataGenerator/FieldGenerator/TypeUuid.php b/typo3/sysext/styleguide/Classes/TcaDataGenerator/FieldGenerator/TypeUuid.php new file mode 100644 index 000000000000..cf91c68a15fc --- /dev/null +++ b/typo3/sysext/styleguide/Classes/TcaDataGenerator/FieldGenerator/TypeUuid.php @@ -0,0 +1,47 @@ +<?php + +declare(strict_types=1); + +/* + * This file is part of the TYPO3 CMS project. + * + * It is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, either version 2 + * of the License, or any later version. + * + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + * + * The TYPO3 project - inspiring people to share! + */ + +namespace TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator; + +use TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGeneratorInterface; + +/** + * Generate data for type=uuid fields + * + * @internal + */ +final class TypeUuid extends AbstractFieldGenerator implements FieldGeneratorInterface +{ + /** + * @var array General match if type=uuid + */ + protected $matchArray = [ + 'fieldConfig' => [ + 'config' => [ + 'type' => 'uuid', + ], + ], + ]; + + /** + * Returns the generated value to be inserted into DB for this field + */ + public function generate(array $data): string + { + return $this->kauderwelschService->getUuid(); + } +} diff --git a/typo3/sysext/styleguide/Classes/TcaDataGenerator/FieldGeneratorResolver.php b/typo3/sysext/styleguide/Classes/TcaDataGenerator/FieldGeneratorResolver.php index 5b8c926b4a18..2f28391fa876 100644 --- a/typo3/sysext/styleguide/Classes/TcaDataGenerator/FieldGeneratorResolver.php +++ b/typo3/sysext/styleguide/Classes/TcaDataGenerator/FieldGeneratorResolver.php @@ -102,6 +102,8 @@ final class FieldGeneratorResolver FieldGenerator\TypePassthrough::class, // General type=user generator FieldGenerator\TypeUser::class, + // General type=uuid generator + FieldGenerator\TypeUuid::class, // type=group FieldGenerator\TypeGroupFal::class, diff --git a/typo3/sysext/styleguide/Configuration/TCA/tx_styleguide_elements_basic.php b/typo3/sysext/styleguide/Configuration/TCA/tx_styleguide_elements_basic.php index e04732ac5e86..60d21674fc60 100644 --- a/typo3/sysext/styleguide/Configuration/TCA/tx_styleguide_elements_basic.php +++ b/typo3/sysext/styleguide/Configuration/TCA/tx_styleguide_elements_basic.php @@ -2,7 +2,7 @@ return [ 'ctrl' => [ - 'title' => 'Form engine elements - input, text, checkbox, radio, none, passthrough, user', + 'title' => 'Form engine elements - input, text, uuid, checkbox, radio, none, passthrough, user', 'label' => 'uid', 'tstamp' => 'tstamp', 'crdate' => 'crdate', @@ -1088,6 +1088,30 @@ backend_layout { ], ], + 'uuid_1' => [ + 'label' => 'uuid_1', + 'description' => 'uuid', + 'config' => [ + 'type' => 'uuid', + ], + ], + 'uuid_2' => [ + 'label' => 'uuid_2', + 'description' => 'uuid without copy icon', + 'config' => [ + 'type' => 'uuid', + 'enableCopyToClipboard' => false, + ], + ], + 'uuid_3' => [ + 'label' => 'uuid_3', + 'description' => 'uuid version 7', + 'config' => [ + 'type' => 'uuid', + 'version' => 7, + ], + ], + 'checkbox_1' => [ 'label' => 'checkbox_1', 'description' => 'field description', @@ -1897,6 +1921,8 @@ backend_layout { text_1, text_2, text_3, text_4, text_5, text_6, text_7, text_9, text_10, text_11, text_12, text_13, text_18, text_14, text_15, text_16, text_17, text_19, text_20, + --div--;uuid, + uuid_1, uuid_2, uuid_3, --div--;check, checkbox_1, checkbox_9, checkbox_2, checkbox_17, checkbox_25, checkbox_18, checkbox_24, checkbox_19, checkbox_26, checkbox_20, checkbox_21, checkbox_22, checkbox_23, checkbox_3, checkbox_4, checkbox_6, checkbox_7, checkbox_8, -- GitLab