Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
romm committed May 18, 2017
1 parent 9fd8011 commit caa06ba
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ public function includeDefaultJavaScriptFiles()
$this->javaScriptFiles[] = 'Formz.Debug.js';
}

foreach ($this->javaScriptFiles as $file) {
foreach (array_reverse($this->javaScriptFiles) as $file) {
$filePath = StringService::get()->getExtensionRelativePath('Resources/Public/JavaScript/' . $file);

$this->includeJsFile($filePath);
$this->includeJsFile($filePath, true);
}

return $this;
Expand Down Expand Up @@ -270,13 +270,14 @@ protected function getJavaScriptFiles()
* @see https://forge.typo3.org/issues/60213
*
* @param string $path
* @param bool $forceOnTop
*/
protected function includeJsFile($path)
protected function includeJsFile($path, $forceOnTop = false)
{
$pageRenderer = $this->assetHandlerConnectorManager->getPageRenderer();

if ($this->environmentService->isEnvironmentInFrontendMode()) {
$pageRenderer->addJsFooterFile($path);
$pageRenderer->addJsFooterFile($path, 'text/javascript', true, $forceOnTop);
} else {
$pageRenderer->addJsFile($path);
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/Controller/FormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ protected function commitMetadata()
{
foreach ($this->processor->getRequestForms() as $formObject) {
if ($formObject->hasForm()
&& $formObject->getPersistenceManager()->formIsPersistent()
&& $formObject->isPersistent()
) {
$formObject->getFormMetadata()->commit();
}
Expand Down
25 changes: 20 additions & 5 deletions Classes/Controller/Processor/ControllerProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ class ControllerProcessor implements SingletonInterface
*/
protected $settings = [];

/**
* @todo
*
* @var string
*/
protected $lastDispatchedRequest;

/**
* @param MvcRequest $request
* @param Arguments $requestArguments
Expand All @@ -91,11 +98,19 @@ public static function prepare(MvcRequest $request, Arguments $requestArguments,
public function setData(MvcRequest $request, Arguments $requestArguments, array $settings)
{
/** @var Request $request */
$this->realRequest = $request;
$this->request = clone $request;
$this->originalRequest = clone $request;
$this->requestArguments = $requestArguments;
$this->settings = $settings;
$dispatchedRequest = $request->getControllerObjectName() . '::' . $request->getControllerActionName();

if ($dispatchedRequest !== $this->lastDispatchedRequest) {
$this->lastDispatchedRequest = $dispatchedRequest;

$this->realRequest = $request;
$this->request = clone $request;
$this->originalRequest = clone $request;
$this->requestArguments = $requestArguments;
$this->settings = $settings;
$this->formArguments = null;
$this->dispatched = false;
}

return $this;
}
Expand Down
9 changes: 8 additions & 1 deletion Classes/Form/FormObject/FormObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Romm\Formz\Exceptions\PropertyNotAccessibleException;
use Romm\Formz\Form\Definition\FormDefinition;
use Romm\Formz\Form\Definition\Step\Step\Step;
use Romm\Formz\Form\Definition\Step\Step\Substep\Substep;
use Romm\Formz\Form\Definition\Step\Step\Substep\SubstepDefinition;
use Romm\Formz\Form\FormInterface;
use Romm\Formz\Form\FormObject\Service\FormObjectRequestData;
Expand Down Expand Up @@ -195,6 +194,14 @@ public function getPersistenceManager()
return $this->persistenceManager;
}

/**
* @return bool
*/
public function isPersistent()
{
return $this->getProxy()->formIsPersistent();
}

/**
* @return bool
*/
Expand Down
27 changes: 25 additions & 2 deletions Classes/Form/FormObject/FormObjectProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Romm\Formz\Domain\Model\FormMetadata;
use Romm\Formz\Error\FormResult;
use Romm\Formz\Form\Definition\Step\Step\Step;
use Romm\Formz\Form\Definition\Step\Step\Substep\Substep;
use Romm\Formz\Form\Definition\Step\Step\Substep\SubstepDefinition;
use Romm\Formz\Form\FormInterface;
use Romm\Formz\Form\FormObject\Service\FormObjectMetadata;
Expand Down Expand Up @@ -53,7 +52,6 @@ class FormObjectProxy
* @var bool
*/
protected $formWasValidated = false;

/**
* @var FormResult
*/
Expand All @@ -69,6 +67,11 @@ class FormObjectProxy
*/
protected $metadata;

/**
* @var bool
*/
protected $formIsPersistent = false;

/**
* @var FormObjectSteps
*/
Expand Down Expand Up @@ -96,6 +99,8 @@ public function getForm()
/**
* Will mark the form as submitted (change the result returned by the
* function `formWasSubmitted()`).
*
* @internal
*/
public function markFormAsSubmitted()
{
Expand All @@ -114,6 +119,8 @@ public function formWasSubmitted()

/**
* Marks the form as validated.
*
* @internal
*/
public function markFormAsValidated()
{
Expand All @@ -128,6 +135,22 @@ public function formWasValidated()
return $this->formWasValidated;
}

/**
* @internal
*/
public function markFormAsPersistent()
{
$this->formIsPersistent = true;
}

/**
* @return bool
*/
public function formIsPersistent()
{
return $this->formIsPersistent;
}

/**
* @return FormResult
*/
Expand Down
28 changes: 18 additions & 10 deletions Classes/Form/FormTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,6 @@ trait FormTrait
*/
protected $validationData = [];

/**
* @return FormObject
* @throws EntryNotFoundException
*/
protected function getFormObject()
{
/** @var FormInterface $this */
return FormObjectFactory::get()->getInstanceWithFormInstance($this);
}

/**
* @return FormMetadataObject
*/
Expand All @@ -70,6 +60,24 @@ public function getValidationResult()
return $this->getFormObject()->getFormResult();
}

/**
* @return bool
*/
public function isPersistent()
{
return $this->getFormObject()->isPersistent();
}

/**
* @return FormObject
* @throws EntryNotFoundException
*/
private function getFormObject()
{
/** @var FormInterface $this */
return FormObjectFactory::get()->getInstanceWithFormInstance($this);
}

/**
* @deprecated This method is deprecated and will be deleted in FormZ v2.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use Romm\Formz\Domain\Model\FormMetadata;
use Romm\Formz\Domain\Repository\FormMetadataRepository;
use Romm\Formz\Form\FormObject\FormObjectFactory;
use Romm\Formz\Middleware\Argument\Arguments;
use Romm\Formz\Middleware\Item\AbstractMiddleware;
use Romm\Formz\Middleware\Item\FormInjection\FormInjectionSignal;
Expand Down Expand Up @@ -78,13 +77,6 @@ public function before(Arguments $arguments)

if ($metadata) {
$form = $formObject->getPersistenceManager()->fetchFirst($metadata);

if ($form) {
$formObject->setForm($form);

$proxy = FormObjectFactory::get()->getProxy($form);
$proxy->setFormHash($metadata->getHash());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ class PersistenceInjectionMiddleware extends DefaultMiddleware implements Preset
public function process()
{
if ($this->getFormObject()->formWasSubmitted()) {
$this->getFormObject()
->getPersistenceManager()
->save($this->getFormObject()->getForm());
$this->getFormObject()->getPersistenceManager()->save();
}
}
}
28 changes: 10 additions & 18 deletions Classes/Persistence/PersistenceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Romm\Formz\Exceptions\InvalidEntryException;
use Romm\Formz\Form\FormInterface;
use Romm\Formz\Form\FormObject\FormObject;
use Romm\Formz\Form\FormObject\FormObjectFactory;

/**
* Manages persistence for a given form object.
Expand All @@ -28,11 +29,6 @@ class PersistenceManager
*/
protected $formObject;

/**
* @var bool
*/
protected $formIsPersistent = false;

/**
* @var bool
*/
Expand All @@ -49,13 +45,12 @@ public function __construct(FormObject $formObject)
/**
* Loops on the registered persistence services and saves the given form
* instance in each one.
*
* @param FormInterface $form
*/
public function save(FormInterface $form)
public function save()
{
$this->initializePersistence();

$form = $this->formObject->getForm();
$metadata = $this->formObject->getFormMetadata();
$identifier = $metadata->getIdentifier();
$persistenceServices = $this->getSortedPersistenceServices();
Expand All @@ -65,7 +60,8 @@ public function save(FormInterface $form)
}

if (count($persistenceServices) > 0) {
$this->formIsPersistent = true;
$proxy = FormObjectFactory::get()->getProxy($form);
$proxy->markFormAsPersistent();
}

/*
Expand Down Expand Up @@ -100,7 +96,11 @@ public function fetchFirst(FormMetadata $metadata)
throw InvalidEntryException::persistenceInvalidEntryFetched($persistence, $form);
}

$this->formIsPersistent = true;
$this->formObject->setForm($form);

$proxy = FormObjectFactory::get()->getProxy($form);
$proxy->setFormHash($metadata->getHash());
$proxy->markFormAsPersistent();

return $form;
}
Expand Down Expand Up @@ -146,12 +146,4 @@ protected function getSortedPersistenceServices()

return $items;
}

/**
* @return bool
*/
public function formIsPersistent()
{
return $this->formIsPersistent;
}
}
36 changes: 18 additions & 18 deletions Classes/Validation/Validator/Form/FormValidatorExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,17 @@ protected function checkFieldValidatorActivation(Field $field)
*/
public function validateFields()
{
// $validatedStep = $this->dataObject->getValidatedStep();
//
// if ($validatedStep
// && $validatedStep->hasSubsteps()
// ) {
// $this->aze();
// } else {
$validatedStep = $this->dataObject->getValidatedStep();

if ($validatedStep
&& $validatedStep->hasSubsteps()
) {
$this->aze();
} else {
foreach ($this->formObject->getDefinition()->getFields() as $field) {
$this->launchFieldValidation($field);
}
// }
}

return $this;
}
Expand All @@ -211,19 +211,19 @@ protected function aze()
$substepDefinition = $this->dataObject->getValidatedStep()->getSubsteps()->getFirstSubstepDefinition();

$conditionProcessor = ConditionProcessorFactory::getInstance()->get($this->formObject);

while ($substepDefinition) {
$phpResult = true;

if ($substepDefinition->hasDetour()) {
foreach ($substepDefinition->getDetourSubsteps() as $detourSubstep) {
$tree = $conditionProcessor->getActivationConditionTreeForSubstep($detourSubstep);
$dataObject = new PhpConditionDataObject($this->formObject->getForm(), $this);
$phpResult = $tree->getPhpResult($dataObject);
}
}
// if ($substepDefinition->hasDetour()) {
// foreach ($substepDefinition->getDetourSubsteps() as $detourSubstep) {
// $tree = $conditionProcessor->getActivationConditionTreeForSubstep($detourSubstep);
//
// $dataObject = new PhpConditionDataObject($this->formObject->getForm(), $this);
//
// $phpResult = $tree->getPhpResult($dataObject);
// }
// }

if (true === $phpResult) {
$supportedFields = $substepDefinition->getSubstep()->getSupportedFields();
Expand Down
2 changes: 1 addition & 1 deletion Classes/ViewHelpers/FormViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ protected function renderHiddenReferrerFields()
$substepDefinition = $this->formObject->getCurrentSubstepDefinition();

if ($substepDefinition) {
$result .= '<input type="hidden" name="' . $this->prefixFieldName('currentSubstep') . '" value="' . $substepDefinition->getUniqueIdentifier() . '" />' . LF;
$result .= '<input type="hidden" fz-substep-field="1" name="' . $this->prefixFieldName('currentSubstep') . '" value="' . $substepDefinition->getUniqueIdentifier() . '" />' . LF;
}

return $result;
Expand Down

0 comments on commit caa06ba

Please sign in to comment.