-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: Make formState initialization extendable
This adds a mechanism to hook into the form state initialization and define custom initializers. Resolves: #152
- Loading branch information
1 parent
800b0f5
commit 70326e6
Showing
6 changed files
with
89 additions
and
21 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
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,40 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neos\Form\FormState; | ||
|
||
/* | ||
* This file is part of the Neos.Form package. | ||
* | ||
* (c) Contributors of the Neos Project - www.neos.io | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
use Neos\Flow\Mvc\ActionRequest; | ||
use Neos\Flow\Security\Cryptography\HashService; | ||
use Neos\Form\Core\Model\FormDefinition; | ||
use Neos\Fusion\Form\Runtime\Domain\FormState; | ||
|
||
class DefaultFormStateInitializer implements FormStateInitializerInterface | ||
{ | ||
/** | ||
* @Flow\Inject | ||
* @var HashService | ||
*/ | ||
protected $hashService; | ||
|
||
public function initializeFormState(FormDefinition $formDefinition, ActionRequest $actionRequest): FormState | ||
{ | ||
$serializedFormStateWithHmac = $actionRequest->getInternalArgument('__state'); | ||
if ($serializedFormStateWithHmac !== null) { | ||
$serializedFormState = $this->hashService->validateAndStripHmac($serializedFormStateWithHmac); | ||
/** @noinspection UnserializeExploitsInspection The unserialize call is safe because of the HMAC check above */ | ||
return unserialize(base64_decode($serializedFormState)); | ||
} | ||
|
||
return new FormState(); | ||
} | ||
} |
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,23 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neos\Form\FormState; | ||
|
||
/* | ||
* This file is part of the Neos.Form package. | ||
* | ||
* (c) Contributors of the Neos Project - www.neos.io | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
use Neos\Flow\Mvc\ActionRequest; | ||
use Neos\Form\Core\Model\FormDefinition; | ||
use Neos\Fusion\Form\Runtime\Domain\FormState; | ||
|
||
interface FormStateInitializerInterface | ||
{ | ||
public function initializeFormState(FormDefinition $formDefinition, ActionRequest $actionRequest): FormState; | ||
} |
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