-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] Implement way to reduce initial flickering
- Loading branch information
1 parent
b458f7b
commit ac2d2e5
Showing
6 changed files
with
178 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace In2code\PowermailCond\Service; | ||
|
||
use In2code\Powermail\Domain\Repository\FormRepository; | ||
use In2code\PowermailCond\Domain\Repository\ConditionContainerRepository; | ||
use In2code\PowermailCond\Exception\MissingPowermailParameterException; | ||
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; | ||
|
||
class ConditionService | ||
{ | ||
protected FormRepository $formRepository; | ||
|
||
protected ConditionContainerRepository $conditionContainerRepository; | ||
|
||
protected TypoScriptFrontendController $typoscriptFrontendController; | ||
|
||
public function __construct() | ||
{ | ||
$this->typoscriptFrontendController = $GLOBALS['TSFE']; | ||
} | ||
|
||
public function injectFormRepository(FormRepository $formRepository): void | ||
{ | ||
$this->formRepository = $formRepository; | ||
} | ||
|
||
public function injectConditionContainerRepository(ConditionContainerRepository $conditionContainerRepository): void | ||
{ | ||
$this->conditionContainerRepository = $conditionContainerRepository; | ||
} | ||
|
||
public function getArguments(array $powermailArguments = []): array | ||
{ | ||
if (empty($powermailArguments['mail']['form'])) { | ||
throw new MissingPowermailParameterException(); | ||
} | ||
|
||
unset($powermailArguments['__referrer'], $powermailArguments['__trustedProperties']); | ||
|
||
/** @var Form $form */ | ||
$form = $this->formRepository->findByIdentifier($powermailArguments['mail']['form']); | ||
|
||
/** @var array<string, Field> $fields */ | ||
$fields = []; | ||
|
||
/** @var Page $page */ | ||
foreach ($form->getPages() as $page) { | ||
/** @var Field $field */ | ||
foreach ($page->getFields() as $field) { | ||
$fields[$field->getMarker()] = $field; | ||
} | ||
} | ||
|
||
foreach ($powermailArguments['field'] ?? [] as $fieldName => $fieldValue) { | ||
if (!array_key_exists($fieldName, $fields)) { | ||
continue; | ||
} | ||
if (is_array($fieldValue)) { | ||
$fieldValue = json_encode($fieldValue, JSON_THROW_ON_ERROR); | ||
} | ||
if (!is_string($fieldValue)) { | ||
throw new UnsupportedVariableTypeException(); | ||
} | ||
$fields[$fieldName]->setText($fieldValue); | ||
} | ||
|
||
$arguments = []; | ||
// Use the forms non-localized UID, because the field is l10n_mode exclude | ||
$conditionContainer = $this->conditionContainerRepository->findOneByForm($form->getUid()); | ||
if ($conditionContainer !== null) { | ||
$arguments = $conditionContainer->applyConditions($form, $powermailArguments); | ||
$this->typoscriptFrontendController->fe_user->setAndSaveSessionData('tx_powermail_cond', $arguments); | ||
unset($arguments['backup'], $arguments['field']); | ||
} | ||
|
||
return $arguments; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace In2code\PowermailCond\ViewHelpers; | ||
|
||
use In2code\Powermail\Domain\Model\Form; | ||
use In2code\PowermailCond\Service\ConditionService; | ||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; | ||
|
||
/** | ||
* Class ConditionsViewHelper | ||
*/ | ||
class ConditionsViewHelper extends AbstractViewHelper | ||
{ | ||
protected ConditionService $conditionService; | ||
|
||
public function injectConditionService(ConditionService $conditionService): void | ||
{ | ||
$this->conditionService = $conditionService; | ||
} | ||
|
||
public function initializeArguments() | ||
{ | ||
parent::initializeArguments(); | ||
$this->registerArgument('form', Form::class, 'Form', true); | ||
} | ||
|
||
/** | ||
* Returns Data Attribute Array to enable validation | ||
* | ||
* @return string | ||
*/ | ||
public function render(): string | ||
{ | ||
/** @var Form $field */ | ||
$form = $this->arguments['form']; | ||
|
||
if ($this->renderingContext->getRequest()->getParsedBody()) { | ||
$params = $this->renderingContext->getRequest()->getParsedBody()['tx_powermail_pi1']; | ||
} else { | ||
$params = ['mail' => ['form' => $form->getUid()]]; | ||
} | ||
|
||
$arguments = $this->conditionService->getArguments($params); | ||
|
||
return json_encode($arguments, JSON_THROW_ON_ERROR); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.