Created
June 4, 2012 09:51
-
-
Save ahsio/2867539 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 | |
| namespace Examplecms\Bundle\ExampleCoreBundle\Form; | |
| use Symfony\Component\Form\AbstractType, | |
| Symfony\Component\Form\FormBuilder; | |
| use Examplecms\Bundle\ExampleCoreBundle\Form\EventListener\SearchCriteriaSubscriber, | |
| Examplecms\Bundle\ExampleCoreBundle\Validator\Constraints as ExamplecmsAssert; | |
| /** | |
| * Search form. | |
| */ | |
| class SearchType extends AbstractType | |
| { | |
| /** | |
| * @param FormBuilder $builder The builder object | |
| * @param array $options Its options | |
| */ | |
| public function buildForm(FormBuilder $builder, array $options) | |
| { | |
| // Take into account search_criteria_1 | |
| if ($options['search_criteria_1']) { | |
| $subscriber = new SearchCriteriaSubscriber( | |
| $builder->getFormFactory(), | |
| array('searchCriteria' => 'search_criteria_1') | |
| ); | |
| $builder->addEventSubscriber($subscriber); | |
| } | |
| // Take into account search_criteria_2 | |
| if ($options['search_criteria_2']) { | |
| $subscriber = new SearchCriteriaSubscriber( | |
| $builder->getFormFactory(), | |
| array('searchCriteria' => 'search_criteria_2') | |
| ); | |
| $builder->addEventSubscriber($subscriber); | |
| } | |
| // Take into account search_criteria_3 | |
| if ($options['search_criteria_3']) { | |
| $subscriber = new SearchCriteriaSubscriber( | |
| $builder->getFormFactory(), | |
| array('searchCriteria' => 'search_criteria_3') | |
| ); | |
| $builder->addEventSubscriber($subscriber); | |
| } | |
| // Take into account search_criteria_4 | |
| if ($options['search_criteria_4']) { | |
| $subscriber = new SearchCriteriaSubscriber( | |
| $builder->getFormFactory(), | |
| array('searchCriteria' => 'search_criteria_4') | |
| ); | |
| $builder->addEventSubscriber($subscriber); | |
| } | |
| // ... | |
| } | |
| } | |
| /** | |
| * @param array $options | |
| * | |
| * @return array | |
| */ | |
| public function getDefaultOptions(array $options) | |
| { | |
| return array( | |
| 'search_criteria_1' => false, | |
| 'search_criteria_2' => false, | |
| 'search_criteria_3' => false, | |
| 'search_criteria_4' => false, | |
| 'search_criteria_5' => false, | |
| 'search_criteria_6' => false, | |
| 'search_criteria_7' => false, | |
| 'search_criteria_8' => false, | |
| 'search_criteria_9' => false, | |
| // ... | |
| 'validation_constraint' => new ExamplecmsAssert\Search(), | |
| ); | |
| } | |
| /** | |
| * @return string The name of the form | |
| */ | |
| public function getName() | |
| { | |
| return 'search'; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment