Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from egeloen/issue-10
[ResolvedFormType] Detect children view dynamically removed
- Loading branch information
Showing
4 changed files
with
88 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Ivory Ordered Form package. | ||
* | ||
* (c) Eric GELOEN <geloen.eric@gmail.com> | ||
* | ||
* For the full copyright and license information, please read the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Ivory\Tests\OrderedForm\Fixtures; | ||
|
||
use Symfony\Component\Form\AbstractTypeExtension; | ||
use Symfony\Component\Form\FormInterface; | ||
use Symfony\Component\Form\FormView; | ||
|
||
/** | ||
* Extra view children extension. | ||
* | ||
* @author GeLo <geloen.eric@gmail.com> | ||
*/ | ||
class RemoveChildrenViewExtension extends AbstractTypeExtension | ||
{ | ||
/** @var array */ | ||
private $names; | ||
|
||
/** | ||
* Creates an extra view children extension. | ||
* | ||
* @param array $names The extra view names. | ||
*/ | ||
public function __construct(array $names) | ||
{ | ||
$this->names = $names; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function finishView(FormView $view, FormInterface $form, array $options) | ||
{ | ||
if ($form->isRoot()) { | ||
return; | ||
} | ||
|
||
foreach ($this->names as $name) { | ||
unset($view[$name]); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getExtendedType() | ||
{ | ||
return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix') | ||
? 'Symfony\Component\Form\Extension\Core\Type\FormType' | ||
: 'form'; | ||
} | ||
} |
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