Skip to content

Commit

Permalink
DefaultFormRenderer: Fix GET Application\UI\Form (#222)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jtojnar authored and dg committed Jul 4, 2019
1 parent 85467ba commit b3356d0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Forms/Rendering/DefaultFormRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ public function renderBegin(): string

if ($this->form->isMethod('get')) {
$el = clone $this->form->getElementPrototype();
$el->action = (string) $el->action;
$query = parse_url($el->action, PHP_URL_QUERY) ?: '';
$el->action = str_replace("?$query", '', $el->action);
$s = '';
Expand Down
22 changes: 22 additions & 0 deletions tests/Forms/Forms.objectAction.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

use Nette\Forms\Form;
use Tester\Assert;

require __DIR__ . '/../bootstrap.php';


Assert::noError(function () {
$form = new Form;
$form->setMethod($form::GET);
$form->setAction(new class {
public function __toString(): string
{
return '/some/link';
}
});

echo $form;
});

0 comments on commit b3356d0

Please sign in to comment.