From b57419651f8bafcdcc55972782090b2c21d8018a Mon Sep 17 00:00:00 2001 From: AJ Meireles Date: Fri, 14 Jun 2024 13:11:15 -0300 Subject: [PATCH] scoped personalization with classes --- .../Personalization/SoftPersonalization.php | 22 +++++++++++++++++++ .../personalization/soft.blade.php | 14 ++++++++++++ 2 files changed, 36 insertions(+) diff --git a/app/Enums/Examples/Personalization/SoftPersonalization.php b/app/Enums/Examples/Personalization/SoftPersonalization.php index 92307690..871d62b0 100644 --- a/app/Enums/Examples/Personalization/SoftPersonalization.php +++ b/app/Enums/Examples/Personalization/SoftPersonalization.php @@ -251,6 +251,28 @@ public function boot(): void HTML; + public const SCOPED_PERSONALIZATION_WITH_CLASS_BLADE_EXAMPLE = <<<'HTML' + + HTML; + + public const SCOPED_PERSONALIZATION_WITH_CLASS_PHP_EXAMPLE = <<<'HTML' + namespace App\ScopedPersonalization; + + class Alert + { + public function __invoke(array $classes): array + { + return [ + 'wrapper' => [ + 'replace' => [ + 'rounded-lg' => 'rounded-full', + ], + ], + ]; + } + } + HTML; + public const DATA = <<<'HTML' [ "id" => null diff --git a/resources/views/documentation/personalization/soft.blade.php b/resources/views/documentation/personalization/soft.blade.php index 7c50a578..30779ae6 100644 --- a/resources/views/documentation/personalization/soft.blade.php +++ b/resources/views/documentation/personalization/soft.blade.php @@ -147,6 +147,20 @@ classes in an easy way in order to make modifications while maintaining the rest in the block name or wrong block name, the application will not generate a visual error for the end user, the personalization will just not be applied. +

+ Starting from version 1.30.0 you can pass a class name that contains a __invoke public method + to the personalize attribute to make the personalization more organized and reusable. + Let's take a look at an example: +

+

Blade:

+ +

PHP:

+ +

+ You may have noticed that in the example above we have an array called $classes as + the parameter of the __invoke method, this array is an array with all classes that + came from the original personalization defined to the component. +