Skip to content

Commit 608d595

Browse files
jtojnardg
authored andcommitted
DefaultFormRenderer: Fix GET Application\UI\Form (#222)
Forms\Form allows to pass stringable objects to setAction method, which is also used by Application\UI\Form to store Application\UI\Link object. DefaultFormRenderer calls string manipulation functions on the Form’s action when rendering, causing it to raise a TypeError when strict types are enabled. To fix this, I am stringifying the action in the DefaultFormRenderer. I have opted to do it there, rather than in the Form::setAction method, in case the Link object is not ready yet at the time the Form is created.
1 parent 00a923b commit 608d595

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/Forms/Rendering/DefaultFormRenderer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ public function renderBegin(): string
167167

168168
if ($this->form->isMethod('get')) {
169169
$el = clone $this->form->getElementPrototype();
170+
$el->action = (string) $el->action;
170171
$query = parse_url($el->action, PHP_URL_QUERY) ?: '';
171172
$el->action = str_replace("?$query", '', $el->action);
172173
$s = '';
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Nette\Forms\Form;
6+
use Tester\Assert;
7+
8+
require __DIR__ . '/../bootstrap.php';
9+
10+
11+
Assert::noError(function () {
12+
$form = new Form;
13+
$form->setMethod($form::GET);
14+
$form->setAction(new class {
15+
public function __toString(): string
16+
{
17+
return '/some/link';
18+
}
19+
});
20+
21+
echo $form;
22+
});

0 commit comments

Comments
 (0)