-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix indirect array access * Attempt at decorating form validator * add FormValidator to docs stub * Fix and simplify FormState array access * Move decoration to form builder service * Moved form state decoration to form builders * Simplified form state replacement --------- Co-authored-by: Matt Glaman <[email protected]>
- Loading branch information
Showing
6 changed files
with
74 additions
and
16 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
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,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Retrofit\Drupal\Form; | ||
|
||
use Drupal\Core\Form\FormBuilder as CoreFormBuilder; | ||
use Drupal\Core\Form\FormStateInterface; | ||
use Retrofit\Drupal\Form\ArrayAccessFormState; | ||
|
||
class FormBuilder extends CoreFormBuilder | ||
{ | ||
/** | ||
* @param FormStateInterface|mixed[] $form_state | ||
* @return mixed[] | ||
*/ | ||
public function buildForm(mixed $form_arg, FormStateInterface|array &$form_state): array | ||
{ | ||
$original_form_state = $form_state; | ||
$form_state = new ArrayAccessFormState(); | ||
if ($original_form_state instanceof FormStateInterface) { | ||
$original_form_state = $original_form_state->getCacheableArray() + get_object_vars($original_form_state); | ||
} | ||
foreach ($original_form_state as $offset => $value) { | ||
$form_state[$offset] = $value; | ||
} | ||
return parent::buildForm($form_arg, $form_state); | ||
} | ||
} |
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