bug #9394 [Form] Fixed form debugger to work even when no view variables are logged (bschussek)
This PR was merged into the master branch.
Discussion
----------
[Form] Fixed form debugger to work even when no view variables are logged
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #9331
| License | MIT
| Doc PR | -
Commits
-------
99a4b7e
[Form] Fixed form debugger to work even when no view variables are logged (e.g. upon redirects)
This commit is contained in:
commit
53315562f2
@ -173,7 +173,7 @@
|
|||||||
|
|
||||||
{% macro form_tree_entry(name, data) %}
|
{% macro form_tree_entry(name, data) %}
|
||||||
<li>
|
<li>
|
||||||
<a href="#details_{{ data.view_vars.id|default("") }}">{{ name }}</a>
|
<a href="#details_{{ data.id }}">{{ name }}</a>
|
||||||
|
|
||||||
{% if data.children is not empty %}
|
{% if data.children is not empty %}
|
||||||
<ul>
|
<ul>
|
||||||
@ -186,7 +186,7 @@
|
|||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% macro form_tree_details(name, data) %}
|
{% macro form_tree_details(name, data) %}
|
||||||
<div class="tree-details" id="details_{{ data.view_vars.id|default("") }}">
|
<div class="tree-details" id="details_{{ data.id }}">
|
||||||
<h2>
|
<h2>
|
||||||
{{ name }}
|
{{ name }}
|
||||||
{% if data.type_class is defined %}
|
{% if data.type_class is defined %}
|
||||||
@ -323,6 +323,7 @@
|
|||||||
</table>
|
</table>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if data.view_vars is defined %}
|
||||||
<h3>View Variables</h3>
|
<h3>View Variables</h3>
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
@ -337,6 +338,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% for childName, childData in data.children %}
|
{% for childName, childData in data.children %}
|
||||||
|
@ -42,6 +42,7 @@ class FormDataExtractor implements FormDataExtractorInterface
|
|||||||
public function extractConfiguration(FormInterface $form)
|
public function extractConfiguration(FormInterface $form)
|
||||||
{
|
{
|
||||||
$data = array(
|
$data = array(
|
||||||
|
'id' => $this->buildId($form),
|
||||||
'type' => $form->getConfig()->getType()->getName(),
|
'type' => $form->getConfig()->getType()->getName(),
|
||||||
'type_class' => get_class($form->getConfig()->getType()->getInnerType()),
|
'type_class' => get_class($form->getConfig()->getType()->getInnerType()),
|
||||||
'synchronized' => $this->valueExporter->exportValue($form->isSynchronized()),
|
'synchronized' => $this->valueExporter->exportValue($form->isSynchronized()),
|
||||||
@ -132,4 +133,22 @@ class FormDataExtractor implements FormDataExtractorInterface
|
|||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recursively builds an HTML ID for a form.
|
||||||
|
*
|
||||||
|
* @param FormInterface $form The form
|
||||||
|
*
|
||||||
|
* @return string The HTML ID
|
||||||
|
*/
|
||||||
|
private function buildId(FormInterface $form)
|
||||||
|
{
|
||||||
|
$id = $form->getName();
|
||||||
|
|
||||||
|
if (null !== $form->getParent()) {
|
||||||
|
$id = $this->buildId($form->getParent()).'_'.$id;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,7 @@ class FormDataExtractorTest extends \PHPUnit_Framework_TestCase
|
|||||||
->getForm();
|
->getForm();
|
||||||
|
|
||||||
$this->assertSame(array(
|
$this->assertSame(array(
|
||||||
|
'id' => 'name',
|
||||||
'type' => 'type_name',
|
'type' => 'type_name',
|
||||||
'type_class' => 'stdClass',
|
'type_class' => 'stdClass',
|
||||||
'synchronized' => 'true',
|
'synchronized' => 'true',
|
||||||
@ -111,6 +112,7 @@ class FormDataExtractorTest extends \PHPUnit_Framework_TestCase
|
|||||||
->getForm();
|
->getForm();
|
||||||
|
|
||||||
$this->assertSame(array(
|
$this->assertSame(array(
|
||||||
|
'id' => 'name',
|
||||||
'type' => 'type_name',
|
'type' => 'type_name',
|
||||||
'type_class' => 'stdClass',
|
'type_class' => 'stdClass',
|
||||||
'synchronized' => 'true',
|
'synchronized' => 'true',
|
||||||
@ -144,6 +146,7 @@ class FormDataExtractorTest extends \PHPUnit_Framework_TestCase
|
|||||||
->getForm();
|
->getForm();
|
||||||
|
|
||||||
$this->assertSame(array(
|
$this->assertSame(array(
|
||||||
|
'id' => 'name',
|
||||||
'type' => 'type_name',
|
'type' => 'type_name',
|
||||||
'type_class' => 'stdClass',
|
'type_class' => 'stdClass',
|
||||||
'synchronized' => 'true',
|
'synchronized' => 'true',
|
||||||
@ -156,6 +159,41 @@ class FormDataExtractorTest extends \PHPUnit_Framework_TestCase
|
|||||||
), $this->dataExtractor->extractConfiguration($form));
|
), $this->dataExtractor->extractConfiguration($form));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testExtractConfigurationBuildsIdRecursively()
|
||||||
|
{
|
||||||
|
$type = $this->getMock('Symfony\Component\Form\ResolvedFormTypeInterface');
|
||||||
|
$type->expects($this->any())
|
||||||
|
->method('getName')
|
||||||
|
->will($this->returnValue('type_name'));
|
||||||
|
$type->expects($this->any())
|
||||||
|
->method('getInnerType')
|
||||||
|
->will($this->returnValue(new \stdClass()));
|
||||||
|
|
||||||
|
$grandParent = $this->createBuilder('grandParent')
|
||||||
|
->setCompound(true)
|
||||||
|
->setDataMapper($this->getMock('Symfony\Component\Form\DataMapperInterface'))
|
||||||
|
->getForm();
|
||||||
|
$parent = $this->createBuilder('parent')
|
||||||
|
->setCompound(true)
|
||||||
|
->setDataMapper($this->getMock('Symfony\Component\Form\DataMapperInterface'))
|
||||||
|
->getForm();
|
||||||
|
$form = $this->createBuilder('name')
|
||||||
|
->setType($type)
|
||||||
|
->getForm();
|
||||||
|
|
||||||
|
$grandParent->add($parent);
|
||||||
|
$parent->add($form);
|
||||||
|
|
||||||
|
$this->assertSame(array(
|
||||||
|
'id' => 'grandParent_parent_name',
|
||||||
|
'type' => 'type_name',
|
||||||
|
'type_class' => 'stdClass',
|
||||||
|
'synchronized' => 'true',
|
||||||
|
'passed_options' => array(),
|
||||||
|
'resolved_options' => array(),
|
||||||
|
), $this->dataExtractor->extractConfiguration($form));
|
||||||
|
}
|
||||||
|
|
||||||
public function testExtractDefaultData()
|
public function testExtractDefaultData()
|
||||||
{
|
{
|
||||||
$form = $this->createBuilder('name')->getForm();
|
$form = $this->createBuilder('name')->getForm();
|
||||||
|
Reference in New Issue
Block a user