Created
January 5, 2017 11:48
-
-
Save screeny05/2abbd890fd7f6095e971ea48131836d9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
/** | |
* Custom EventExtension needed to subscribe to global buildForm Event | |
*/ | |
use Shopware\Bundle\FormBundle\Extension\EventExtension; | |
use Symfony\Component\Form\AbstractTypeExtension; | |
use Symfony\Component\Form\FormEvent; | |
use Symfony\Component\Form\FormEvents; | |
use Symfony\Component\Form\FormBuilderInterface; | |
class Shopware_Components_Foobar_EventExtension extends AbstractTypeExtension | |
{ | |
/** @var AbstractTypeExtension */ | |
private $innerExtension = null; | |
/** @var \Enlight_Event_EventManager */ | |
private $eventManager; | |
/** | |
* FormTypeEventExtension constructor. | |
* @param AbstractTypeExtension $innerExtension | |
*/ | |
public function __construct(AbstractTypeExtension $innerExtension, \Enlight_Event_EventManager $eventManager) | |
{ | |
$this->innerExtension = $innerExtension; | |
$this->eventManager = $eventManager; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function buildForm(FormBuilderInterface $builder, array $options) | |
{ | |
// add custom event to be able to subscribe to post_submit-events | |
$this->eventManager->notify('Shopware_Form_Builder_BUILD_FORM', [ | |
'reference' => $builder->getForm()->getConfig()->getType()->getName(), | |
'builder' => $builder, | |
'options' => $options | |
]); | |
return $this->innerExtension->buildForm($builder, $options); | |
} | |
/** | |
* Returns the name of the type being extended. | |
* | |
* @return string The name of the type being extended | |
*/ | |
public function getExtendedType() | |
{ | |
return $this->innerExtension->getExtendedType(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment