Skip to content

Commit

Permalink
Merge pull request #49 from bwaidelich/task-expose-serialized-formstate
Browse files Browse the repository at this point in the history
TASK: Expose serialized form state from the Form runtime
  • Loading branch information
kdambekalns committed Jul 26, 2017
2 parents 9b22bc7 + 5334f9b commit bc3c7d1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
10 changes: 10 additions & 0 deletions Classes/Core/Runtime/FormRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,16 @@ public function getFormState()
return $this->formState;
}

/**
* @return string
* @internal
*/
public function getSerializedFormState()
{
$serializedFormState = base64_encode(serialize($this->getFormState()));
return $this->hashService->appendHmac($serializedFormState);
}

/**
* Get all rendering options
*
Expand Down
15 changes: 5 additions & 10 deletions Classes/ViewHelpers/FormViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,16 @@
* source code.
*/

use Neos\FluidAdaptor\ViewHelpers\FormViewHelper as FluidFormViewHelper;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Mvc\ActionRequest;
use Neos\FluidAdaptor\ViewHelpers\FormViewHelper as FluidFormViewHelper;
use Neos\Form\Core\Runtime\FormRuntime;
use TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder;

/**
* Custom form ViewHelper that renders the form state instead of referrer fields
*/
class FormViewHelper extends FluidFormViewHelper
{
/**
* @Flow\Inject
* @var \Neos\Flow\Security\Cryptography\HashService
*/
protected $hashService;

/**
* Renders hidden form fields for referrer information about
* the current request.
Expand All @@ -38,8 +32,9 @@ protected function renderHiddenReferrerFields()
$tagBuilder = new TagBuilder('input');
$tagBuilder->addAttribute('type', 'hidden');
$tagBuilder->addAttribute('name', $this->prefixFieldName('__state'));
$serializedFormState = base64_encode(serialize($this->arguments['object']->getFormState()));
$tagBuilder->addAttribute('value', $this->hashService->appendHmac($serializedFormState));
/** @var FormRuntime $formRuntime */
$formRuntime = $this->arguments['object'];
$tagBuilder->addAttribute('value', $formRuntime->getSerializedFormState());
return $tagBuilder->render();
}

Expand Down

0 comments on commit bc3c7d1

Please sign in to comment.