From 2fa84b662046cefdc1c000c5ec002824221651ca Mon Sep 17 00:00:00 2001 From: Ambroise Maupate Date: Fri, 12 Jul 2024 12:21:07 +0200 Subject: [PATCH] fix: Fixed simple.html.twig Twig template with rz-accent-color for login and custom-form --- .../src/Controller/CustomFormController.php | 11 +++- .../src/Controller/HealthCheckController.php | 17 ++---- .../src/Controller/RedirectionController.php | 10 +--- .../CustomForm/CustomFormAnswerSerializer.php | 15 +---- .../src/CustomForm/CustomFormHelper.php | 44 +++------------ .../CustomForm/CustomFormHelperFactory.php | 28 ++-------- .../Message/CustomFormAnswerNotifyMessage.php | 23 ++------ .../DataCollector/RequestDataCollector.php | 11 ++-- .../customForm/base_custom_form.html.twig | 56 +++++++++++-------- .../templates/customForm/customForm.html.twig | 2 +- .../customForm/customFormSent.html.twig | 2 +- .../src/Controller/SecurityController.php | 25 ++++----- .../templates/simple.html.twig | 21 +++---- .../src/Resources/views/simple.html.twig | 54 ------------------ 14 files changed, 93 insertions(+), 226 deletions(-) delete mode 100644 lib/Rozier/src/Resources/views/simple.html.twig diff --git a/lib/RoadizCoreBundle/src/Controller/CustomFormController.php b/lib/RoadizCoreBundle/src/Controller/CustomFormController.php index bdb06122..179d96cf 100644 --- a/lib/RoadizCoreBundle/src/Controller/CustomFormController.php +++ b/lib/RoadizCoreBundle/src/Controller/CustomFormController.php @@ -208,9 +208,14 @@ public function prepareAndHandleCustomFormAssignation( ?string $emailSender = null, bool $prefix = true ) { - $assignation = []; - $assignation['customForm'] = $customFormsEntity; - $assignation['fields'] = $customFormsEntity->getFields(); + $assignation = [ + 'customForm' => $customFormsEntity, + 'fields' => $customFormsEntity->getFields(), + 'head' => [ + 'siteTitle' => $this->settingsBag->get('site_name'), + 'mainColor' => $this->settingsBag->get('main_color'), + ] + ]; $helper = $this->customFormHelperFactory->createHelper($customFormsEntity); $form = $helper->getForm( $request, diff --git a/lib/RoadizCoreBundle/src/Controller/HealthCheckController.php b/lib/RoadizCoreBundle/src/Controller/HealthCheckController.php index 4bff540b..952f17f1 100644 --- a/lib/RoadizCoreBundle/src/Controller/HealthCheckController.php +++ b/lib/RoadizCoreBundle/src/Controller/HealthCheckController.php @@ -11,21 +11,12 @@ final class HealthCheckController { - private ?string $healthCheckToken; - private ?string $appVersion; - private ?string $cmsVersion; - private ?string $cmsVersionPrefix; - public function __construct( - ?string $healthCheckToken, - ?string $appVersion, - ?string $cmsVersion, - ?string $cmsVersionPrefix + private readonly ?string $healthCheckToken, + private readonly ?string $appVersion, + private readonly ?string $cmsVersion, + private readonly ?string $cmsVersionPrefix ) { - $this->healthCheckToken = $healthCheckToken; - $this->appVersion = $appVersion; - $this->cmsVersion = $cmsVersion; - $this->cmsVersionPrefix = $cmsVersionPrefix; } public function __invoke(Request $request): JsonResponse diff --git a/lib/RoadizCoreBundle/src/Controller/RedirectionController.php b/lib/RoadizCoreBundle/src/Controller/RedirectionController.php index bffc5dc4..6ede96a6 100644 --- a/lib/RoadizCoreBundle/src/Controller/RedirectionController.php +++ b/lib/RoadizCoreBundle/src/Controller/RedirectionController.php @@ -14,18 +14,10 @@ final class RedirectionController { - private UrlGeneratorInterface $urlGenerator; - - public function __construct(UrlGeneratorInterface $urlGenerator) + public function __construct(private readonly UrlGeneratorInterface $urlGenerator) { - $this->urlGenerator = $urlGenerator; } - /** - * @param Request $request - * @param Redirection $redirection - * @return RedirectResponse - */ public function redirectAction(Request $request, Redirection $redirection): RedirectResponse { if (null !== $redirection->getRedirectNodeSource()) { diff --git a/lib/RoadizCoreBundle/src/CustomForm/CustomFormAnswerSerializer.php b/lib/RoadizCoreBundle/src/CustomForm/CustomFormAnswerSerializer.php index 9e3b7774..cdf08b8e 100644 --- a/lib/RoadizCoreBundle/src/CustomForm/CustomFormAnswerSerializer.php +++ b/lib/RoadizCoreBundle/src/CustomForm/CustomFormAnswerSerializer.php @@ -11,23 +11,10 @@ class CustomFormAnswerSerializer { - /** - * @var UrlGeneratorInterface - */ - protected UrlGeneratorInterface $urlGenerator; - - /** - * @param UrlGeneratorInterface $urlGenerator - */ - public function __construct(UrlGeneratorInterface $urlGenerator) + public function __construct(protected readonly UrlGeneratorInterface $urlGenerator) { - $this->urlGenerator = $urlGenerator; } - /** - * @param CustomFormAnswer $answer - * @return array - */ public function toSimpleArray(CustomFormAnswer $answer): array { $answers = [ diff --git a/lib/RoadizCoreBundle/src/CustomForm/CustomFormHelper.php b/lib/RoadizCoreBundle/src/CustomForm/CustomFormHelper.php index 034d9a87..1a2dcb27 100644 --- a/lib/RoadizCoreBundle/src/CustomForm/CustomFormHelper.php +++ b/lib/RoadizCoreBundle/src/CustomForm/CustomFormHelper.php @@ -17,6 +17,7 @@ use RZ\Roadiz\Documents\Events\DocumentCreatedEvent; use RZ\Roadiz\Documents\Models\DocumentInterface; use RZ\Roadiz\Utils\StringHandler; +use Symfony\Component\DependencyInjection\Attribute\Exclude; use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\File\UploadedFile; @@ -24,39 +25,19 @@ use Symfony\Component\String\Slugger\AsciiSlugger; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; +#[Exclude] class CustomFormHelper { public const ARRAY_SEPARATOR = ', '; - protected AbstractDocumentFactory $documentFactory; - protected ObjectManager $em; - protected CustomForm $customForm; - protected FormFactoryInterface $formFactory; - protected Settings $settingsBag; - protected EventDispatcherInterface $eventDispatcher; - - /** - * @param ObjectManager $em - * @param CustomForm $customForm - * @param AbstractDocumentFactory $documentFactory - * @param FormFactoryInterface $formFactory - * @param Settings $settingsBag - * @param EventDispatcherInterface $eventDispatcher - */ public function __construct( - ObjectManager $em, - CustomForm $customForm, - AbstractDocumentFactory $documentFactory, - FormFactoryInterface $formFactory, - Settings $settingsBag, - EventDispatcherInterface $eventDispatcher + protected readonly ObjectManager $em, + protected readonly CustomForm $customForm, + protected readonly AbstractDocumentFactory $documentFactory, + protected readonly FormFactoryInterface $formFactory, + protected readonly Settings $settingsBag, + protected readonly EventDispatcherInterface $eventDispatcher ) { - $this->em = $em; - $this->customForm = $customForm; - $this->documentFactory = $documentFactory; - $this->formFactory = $formFactory; - $this->settingsBag = $settingsBag; - $this->eventDispatcher = $eventDispatcher; } /** @@ -197,9 +178,6 @@ protected function handleUploadedFile( return $document; } - /** - * @return Folder|null - */ protected function getDocumentFolderForCustomForm(): ?Folder { return $this->em->getRepository(Folder::class) @@ -210,11 +188,7 @@ protected function getDocumentFolderForCustomForm(): ?Folder ); } - /** - * @param mixed $rawValue - * @return string - */ - private function formValueToString($rawValue): string + private function formValueToString(mixed $rawValue): string { if ($rawValue instanceof \DateTimeInterface) { return $rawValue->format('Y-m-d H:i:s'); diff --git a/lib/RoadizCoreBundle/src/CustomForm/CustomFormHelperFactory.php b/lib/RoadizCoreBundle/src/CustomForm/CustomFormHelperFactory.php index 602c7133..a04deb5e 100644 --- a/lib/RoadizCoreBundle/src/CustomForm/CustomFormHelperFactory.php +++ b/lib/RoadizCoreBundle/src/CustomForm/CustomFormHelperFactory.php @@ -13,31 +13,13 @@ final class CustomFormHelperFactory { - protected PrivateDocumentFactory $privateDocumentFactory; - protected ObjectManager $em; - protected FormFactoryInterface $formFactory; - protected Settings $settingsBag; - protected EventDispatcherInterface $eventDispatcher; - - /** - * @param PrivateDocumentFactory $privateDocumentFactory - * @param ObjectManager $em - * @param FormFactoryInterface $formFactory - * @param Settings $settingsBag - * @param EventDispatcherInterface $eventDispatcher - */ public function __construct( - PrivateDocumentFactory $privateDocumentFactory, - ObjectManager $em, - FormFactoryInterface $formFactory, - Settings $settingsBag, - EventDispatcherInterface $eventDispatcher + private readonly PrivateDocumentFactory $privateDocumentFactory, + private readonly ObjectManager $em, + private readonly FormFactoryInterface $formFactory, + private readonly Settings $settingsBag, + private readonly EventDispatcherInterface $eventDispatcher ) { - $this->privateDocumentFactory = $privateDocumentFactory; - $this->em = $em; - $this->formFactory = $formFactory; - $this->settingsBag = $settingsBag; - $this->eventDispatcher = $eventDispatcher; } public function createHelper(CustomForm $customForm): CustomFormHelper diff --git a/lib/RoadizCoreBundle/src/CustomForm/Message/CustomFormAnswerNotifyMessage.php b/lib/RoadizCoreBundle/src/CustomForm/Message/CustomFormAnswerNotifyMessage.php index 8f092728..ce56e283 100644 --- a/lib/RoadizCoreBundle/src/CustomForm/Message/CustomFormAnswerNotifyMessage.php +++ b/lib/RoadizCoreBundle/src/CustomForm/Message/CustomFormAnswerNotifyMessage.php @@ -8,23 +8,12 @@ final class CustomFormAnswerNotifyMessage implements AsyncMessage { - private int $customFormAnswerId; - private string $title; - private string $senderAddress; - private string $locale; - - /** - * @param int $customFormAnswerId - * @param string $title - * @param string $senderAddress - * @param string $locale - */ - public function __construct(int $customFormAnswerId, string $title, string $senderAddress, string $locale) - { - $this->customFormAnswerId = $customFormAnswerId; - $this->title = $title; - $this->senderAddress = $senderAddress; - $this->locale = $locale; + public function __construct( + private readonly int $customFormAnswerId, + private readonly string $title, + private readonly string $senderAddress, + private readonly string $locale + ) { } public function getCustomFormAnswerId(): int diff --git a/lib/RoadizCoreBundle/src/DataCollector/RequestDataCollector.php b/lib/RoadizCoreBundle/src/DataCollector/RequestDataCollector.php index 8c2c84bd..27f5bc2e 100644 --- a/lib/RoadizCoreBundle/src/DataCollector/RequestDataCollector.php +++ b/lib/RoadizCoreBundle/src/DataCollector/RequestDataCollector.php @@ -11,13 +11,10 @@ final class RequestDataCollector extends AbstractDataCollector { - private ?string $cmsVersion = null; - private ?string $cmsVersionPrefix = null; - - public function __construct(string $cmsVersion, string $cmsVersionPrefix) - { - $this->cmsVersion = $cmsVersion; - $this->cmsVersionPrefix = $cmsVersionPrefix; + public function __construct( + private readonly string $cmsVersion, + private readonly string $cmsVersionPrefix + ) { } /** diff --git a/lib/RoadizCoreBundle/templates/customForm/base_custom_form.html.twig b/lib/RoadizCoreBundle/templates/customForm/base_custom_form.html.twig index 0111cce7..e1b14ada 100644 --- a/lib/RoadizCoreBundle/templates/customForm/base_custom_form.html.twig +++ b/lib/RoadizCoreBundle/templates/customForm/base_custom_form.html.twig @@ -1,26 +1,34 @@ -{% set formattedLocale = request.locale|replace({'_': '-'})|lower %} +{% set formattedLocale = app.request.locale|replace({'_': '-'})|lower %} - - - - - {% block title %}{{ head.siteTitle }}{% endblock %} - - - - {% include '@RoadizRozier/partials/css-inject.html.twig' %} - - - - - - -
- {% block content %} -

{% trans %}Welcome{% endtrans %}

- {% endblock %} -
- - - + + + + + {% block title %}{{ head.siteTitle }}{% endblock %} + + + {% include '@RoadizRozier/admin/meta-icon.html.twig' %} + {# CSS scripts inclusions / Using webpack #} + {% include '@RoadizRozier/partials/css-inject.html.twig' %} + {% if head.mainColor %} + + {% endif %} + + + +{% include '@RoadizRozier/includes/messages.html.twig' %} +
+ {% block content %} +

{% trans %}Welcome{% endtrans %}

+ {% endblock %} +
+{% block customScripts %}{% endblock %} + diff --git a/lib/RoadizCoreBundle/templates/customForm/customForm.html.twig b/lib/RoadizCoreBundle/templates/customForm/customForm.html.twig index 86d9b857..893ceff0 100644 --- a/lib/RoadizCoreBundle/templates/customForm/customForm.html.twig +++ b/lib/RoadizCoreBundle/templates/customForm/customForm.html.twig @@ -1,6 +1,6 @@ {% extends '@RoadizCore/customForm/base_custom_form.html.twig' %} -{% block title %}{{ customForm.displayName }}{% endblock %} +{% block title %}{{ customForm.displayName }} | {{ parent() }}{% endblock %} {% block content %}
diff --git a/lib/RoadizCoreBundle/templates/customForm/customFormSent.html.twig b/lib/RoadizCoreBundle/templates/customForm/customFormSent.html.twig index e9c4a655..2127bfd2 100644 --- a/lib/RoadizCoreBundle/templates/customForm/customFormSent.html.twig +++ b/lib/RoadizCoreBundle/templates/customForm/customFormSent.html.twig @@ -1,6 +1,6 @@ {% extends '@RoadizCore/customForm/base_custom_form.html.twig' %} -{% block title %}{{ customForm.displayName }}{% endblock %} +{% block title %}{{ customForm.displayName }} | {{ parent() }}{% endblock %} {% block content %}
diff --git a/lib/RoadizRozierBundle/src/Controller/SecurityController.php b/lib/RoadizRozierBundle/src/Controller/SecurityController.php index 4809b28e..e354ce2e 100644 --- a/lib/RoadizRozierBundle/src/Controller/SecurityController.php +++ b/lib/RoadizRozierBundle/src/Controller/SecurityController.php @@ -11,28 +11,19 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; use Themes\Rozier\RozierServiceRegistry; class SecurityController extends AbstractController { - private OAuth2LinkGenerator $oAuth2LinkGenerator; - private LoggerInterface $logger; - private Settings $settingsBag; - private RozierServiceRegistry $rozierServiceRegistry; - public function __construct( - OAuth2LinkGenerator $oAuth2LinkGenerator, - LoggerInterface $logger, - Settings $settingsBag, - RozierServiceRegistry $rozierServiceRegistry + private readonly OAuth2LinkGenerator $oAuth2LinkGenerator, + private readonly LoggerInterface $logger, + private readonly Settings $settingsBag, + private readonly RozierServiceRegistry $rozierServiceRegistry ) { - $this->oAuth2LinkGenerator = $oAuth2LinkGenerator; - $this->logger = $logger; - $this->settingsBag = $settingsBag; - $this->rozierServiceRegistry = $rozierServiceRegistry; } #[Route(path: '/rz-admin/login', name: 'roadiz_rozier_login')] @@ -49,7 +40,11 @@ public function login(Request $request, AuthenticationUtils $authenticationUtils $assignation = [ 'last_username' => $lastUsername, 'error' => $error, - 'themeServices' => $this->rozierServiceRegistry + 'themeServices' => $this->rozierServiceRegistry, + 'head' => [ + 'siteTitle' => $this->settingsBag->get('site_name') . ' backstage', + 'mainColor' => $this->settingsBag->get('main_color'), + ] ]; try { diff --git a/lib/RoadizRozierBundle/templates/simple.html.twig b/lib/RoadizRozierBundle/templates/simple.html.twig index 73741a77..509901ac 100644 --- a/lib/RoadizRozierBundle/templates/simple.html.twig +++ b/lib/RoadizRozierBundle/templates/simple.html.twig @@ -4,26 +4,27 @@ - {% block title %}{% trans %}back_office{% endtrans %}{% endblock %} + {% block title %}{% trans %}back_office{% endtrans %}: {{ head.siteTitle|default(meta.siteName) }}{% endblock %} {% include '@RoadizRozier/admin/meta-icon.html.twig' %} {# CSS scripts inclusions / Using webpack #} {% include '@RoadizRozier/partials/css-inject.html.twig' %} - + {% if head.mainColor %} + + {% endif %} {% include '@RoadizRozier/includes/messages.html.twig' %}
-
{% block content %} diff --git a/lib/Rozier/src/Resources/views/simple.html.twig b/lib/Rozier/src/Resources/views/simple.html.twig deleted file mode 100644 index e68d5a95..00000000 --- a/lib/Rozier/src/Resources/views/simple.html.twig +++ /dev/null @@ -1,54 +0,0 @@ -{% set formattedLocale = app.request.locale|replace({'_': '-'})|lower %} - - - - - - {% block title %}{% trans %}back_office{% endtrans %}{% endblock %} - - - {% include '@RoadizRozier/admin/meta-icon.html.twig' %} - {# CSS scripts inclusions / Using webpack #} - {% include '@RoadizRozier/partials/css-inject.html.twig' %} - {% if head.mainColor %} - - {% endif %} - - - - {% include '@RoadizRozier/includes/messages.html.twig' %} -
- -
-
- {% block content %} -

{% trans %}welcome{% endtrans %}

- {% endblock %} -
-
- - - {% if head.devMode %} - - {% else %} - - {% endif %} - {# JS scripts inclusions / Using webpack #} - {% include '@RoadizRozier/partials/simple-js-inject.html.twig' %} - {% block customScripts %}{% endblock %} - -