Skip to content

Commit

Permalink
fix: Fixed simple.html.twig Twig template with rz-accent-color for lo…
Browse files Browse the repository at this point in the history
…gin and custom-form
  • Loading branch information
ambroisemaupate committed Jul 12, 2024
1 parent 06548e2 commit 2fa84b6
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 226 deletions.
11 changes: 8 additions & 3 deletions lib/RoadizCoreBundle/src/Controller/CustomFormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 4 additions & 13 deletions lib/RoadizCoreBundle/src/Controller/HealthCheckController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 1 addition & 9 deletions lib/RoadizCoreBundle/src/Controller/RedirectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
44 changes: 9 additions & 35 deletions lib/RoadizCoreBundle/src/CustomForm/CustomFormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,27 @@
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;
use Symfony\Component\HttpFoundation\Request;
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;
}

/**
Expand Down Expand Up @@ -197,9 +178,6 @@ protected function handleUploadedFile(
return $document;
}

/**
* @return Folder|null
*/
protected function getDocumentFolderForCustomForm(): ?Folder
{
return $this->em->getRepository(Folder::class)
Expand All @@ -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');
Expand Down
28 changes: 5 additions & 23 deletions lib/RoadizCoreBundle/src/CustomForm/CustomFormHelperFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 4 additions & 7 deletions lib/RoadizCoreBundle/src/DataCollector/RequestDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
{% set formattedLocale = request.locale|replace({'_': '-'})|lower %}
{% set formattedLocale = app.request.locale|replace({'_': '-'})|lower %}
<!DOCTYPE html>
<html class="no-js" lang="{{ formattedLocale }}"{% if request.locale is rtl %} dir="rtl"{% endif %}>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>{% block title %}{{ head.siteTitle }}{% endblock %}</title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1" />

{% include '@RoadizRozier/partials/css-inject.html.twig' %}

<script src="{{ asset('vendor/modernizr.custom.50380.js', 'Rozier') }}"></script>
</head>
<body id="custom-form-front">

<!-- Add your site or application content here -->
<section id="main-content">
{% block content %}
<h1>{% trans %}Welcome{% endtrans %}</h1>
{% endblock %}
</section>

<!-- ##debug_panel## -->
</body>
<html class="no-js" lang="{{ formattedLocale }}"{% if app.request.locale is rtl %} dir="rtl"{% endif %}>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>{% block title %}{{ head.siteTitle }}{% endblock %}</title>
<meta name="description" content="{% block description %}{% trans %}back_office{% endtrans %}{% endblock %}">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
{% include '@RoadizRozier/admin/meta-icon.html.twig' %}
{# CSS scripts inclusions / Using webpack #}
{% include '@RoadizRozier/partials/css-inject.html.twig' %}
{% if head.mainColor %}
<style>
:root {
--rz-accent-color: {{ head.mainColor|raw }};
--rz-accent-color-lighter: color-mix(in srgb, var(--rz-accent-color) var(--color-light-mix), white);
--rz-accent-color-darker: color-mix(in srgb, var(--rz-accent-color) var(--color-darker-mix), black);
--rz-accent-color-darkest: color-mix(in srgb, var(--rz-accent-color) var(--color-darkest-mix), black);
}
</style>
{% endif %}
<script src="{{ asset('vendor/modernizr.custom.50380.js', 'Rozier') }}"></script>
</head>
<body id="custom-form-front">
{% include '@RoadizRozier/includes/messages.html.twig' %}
<section id="main-content">
{% block content %}
<h1>{% trans %}Welcome{% endtrans %}</h1>
{% endblock %}
</section>
{% block customScripts %}{% endblock %}
</body>
</html>
Original file line number Diff line number Diff line change
@@ -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 %}
<section class="content-global">
Expand Down
Original file line number Diff line number Diff line change
@@ -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 %}
<section class="content-global">
Expand Down
25 changes: 10 additions & 15 deletions lib/RoadizRozierBundle/src/Controller/SecurityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')]
Expand All @@ -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 {
Expand Down
Loading

0 comments on commit 2fa84b6

Please sign in to comment.