Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merged branch bschussek/form-debugger (PR #9082)
This PR was merged into the master branch. Discussion ---------- [Form] Implemented form debugger Same as #9021 (kudos to @digitalkaoz!), with some added caramel. | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - **Note:** Please keep in mind that this is a first version only. Not all features (especially UX/UI-wise) that I'd like to see are in there, but it's good enough for a first merge. Commits ------- 89509d9 [Form] Improved form debugger f56c577 [HttpKernel] Extracted value exporting logic of DataCollector into a separate ValueExporter class 56d78ed [Form] Decoupled methods of ResolvedFormType so that they can be overridden individually by decorators a994a5d [Form] Merged subsriber/collector, also collect valid forms 1972a91 [Form] Added form debug collector
- Loading branch information
Showing
28 changed files
with
2,733 additions
and
209 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
26 changes: 26 additions & 0 deletions
26
src/Symfony/Bundle/FrameworkBundle/Resources/config/form_debug.xml
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,26 @@ | ||
<?xml version="1.0" ?> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<parameters> | ||
<parameter key="form.resolved_type_factory.data_collector_proxy.class">Symfony\Component\Form\Extension\DataCollector\Proxy\ResolvedTypeFactoryDataCollectorProxy</parameter> | ||
<parameter key="form.type_extension.form.data_collector.class">Symfony\Component\Form\Extension\DataCollector\Type\DataCollectorTypeExtension</parameter> | ||
</parameters> | ||
|
||
<services> | ||
<service id="form.resolved_type_factory" class="%form.resolved_type_factory.data_collector_proxy.class%"> | ||
<argument type="service"> | ||
<service class="%form.resolved_type_factory.class%" /> | ||
</argument> | ||
<argument type="service" id="data_collector.form" /> | ||
</service> | ||
|
||
<!-- DataCollectorTypeExtension --> | ||
<service id="form.type_extension.form.data_collector" class="%form.type_extension.form.data_collector.class%"> | ||
<tag name="form.type_extension" alias="form" /> | ||
<argument type="service" id="data_collector.form" /> | ||
</service> | ||
</services> | ||
</container> |
345 changes: 345 additions & 0 deletions
345
src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/form.html.twig
Large diffs are not rendered by default.
Oops, something went wrong.
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
45 changes: 45 additions & 0 deletions
45
src/Symfony/Component/Form/Extension/DataCollector/DataCollectorExtension.php
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,45 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Form\Extension\DataCollector; | ||
|
||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\Form\AbstractExtension; | ||
|
||
/** | ||
* Extension for collecting data of the forms on a page. | ||
* | ||
* @since 2.4 | ||
* @author Robert Schönthal <robert.schoenthal@gmail.com> | ||
* @author Bernhard Schussek <bschussek@gmail.com> | ||
*/ | ||
class DataCollectorExtension extends AbstractExtension | ||
{ | ||
/** | ||
* @var EventSubscriberInterface | ||
*/ | ||
private $dataCollector; | ||
|
||
public function __construct(FormDataCollectorInterface $dataCollector) | ||
{ | ||
$this->dataCollector = $dataCollector; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function loadTypeExtensions() | ||
{ | ||
return array( | ||
new Type\DataCollectorTypeExtension($this->dataCollector) | ||
); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
src/Symfony/Component/Form/Extension/DataCollector/EventListener/DataCollectorListener.php
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,85 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Form\Extension\DataCollector\EventListener; | ||
|
||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\Form\Extension\DataCollector\FormDataCollectorInterface; | ||
use Symfony\Component\Form\FormEvent; | ||
use Symfony\Component\Form\FormEvents; | ||
|
||
/** | ||
* Listener that invokes a data collector for the {@link FormEvents::POST_SET_DATA} | ||
* and {@link FormEvents::POST_SUBMIT} events. | ||
* | ||
* @since 2.4 | ||
* @author Bernhard Schussek <bschussek@gmail.com> | ||
*/ | ||
class DataCollectorListener implements EventSubscriberInterface | ||
{ | ||
/** | ||
* @var FormDataCollectorInterface | ||
*/ | ||
private $dataCollector; | ||
|
||
public function __construct(FormDataCollectorInterface $dataCollector) | ||
{ | ||
$this->dataCollector = $dataCollector; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public static function getSubscribedEvents() | ||
{ | ||
return array( | ||
// High priority in order to be called as soon as possible | ||
FormEvents::POST_SET_DATA => array('postSetData', 255), | ||
// Low priority in order to be called as late as possible | ||
FormEvents::POST_SUBMIT => array('postSubmit', -255), | ||
); | ||
} | ||
|
||
/** | ||
* Listener for the {@link FormEvents::POST_SET_DATA} event. | ||
* | ||
* @param FormEvent $event The event object | ||
*/ | ||
public function postSetData(FormEvent $event) | ||
{ | ||
if ($event->getForm()->isRoot()) { | ||
// Collect basic information about each form | ||
$this->dataCollector->collectConfiguration($event->getForm()); | ||
|
||
// Collect the default data | ||
$this->dataCollector->collectDefaultData($event->getForm()); | ||
} | ||
} | ||
|
||
/** | ||
* Listener for the {@link FormEvents::POST_SUBMIT} event. | ||
* | ||
* @param FormEvent $event The event object | ||
*/ | ||
public function postSubmit(FormEvent $event) | ||
{ | ||
if ($event->getForm()->isRoot()) { | ||
// Collect the submitted data of each form | ||
$this->dataCollector->collectSubmittedData($event->getForm()); | ||
|
||
// Assemble a form tree | ||
// This is done again in collectViewVariables(), but that method | ||
// is not guaranteed to be called (i.e. when no view is created) | ||
$this->dataCollector->buildPreliminaryFormTree($event->getForm()); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.