Created
January 20, 2013 22:03
-
-
Save renepardon/4582103 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 Admin\Form\Blog; | |
use Blog\Entity\Article as ArticleEntity; | |
use Zend\Form\Fieldset; | |
use Zend\Stdlib\Hydrator\ObjectProperty; | |
use Zend\InputFilter\InputFilterProviderInterface; | |
class ArticleFieldset | |
extends Fieldset | |
implements InputFilterProviderInterface | |
{ | |
public function __construct($entityManager, $name = 'article') | |
{ | |
parent::__construct($name); | |
$this->setObject(new ArticleEntity()) | |
->setHydrator(new ObjectProperty()); | |
$this->add( | |
array( | |
'type' => 'Zend\Form\Element\Hidden', | |
'name' => 'id', | |
) | |
); | |
$this->add( | |
array( | |
'type' => 'Zend\Form\Element\Text', | |
'name' => 'date', | |
'options' => array( | |
'label' => 'Date', | |
), | |
'attributes' => array( | |
'required' => true, | |
), | |
) | |
); | |
$this->add( | |
array( | |
'type' => 'Zend\Form\Element\Textarea', | |
'name' => 'content', | |
'options' => array( | |
'label' => 'Content', | |
), | |
'attributes' => array( | |
'required' => true, | |
), | |
) | |
); | |
$this->add( | |
array( | |
'type' => 'Zend\Form\Element\Text', | |
'name' => 'title', | |
'options' => array( | |
'label' => 'Title', | |
), | |
'attributes' => array( | |
'required' => true, | |
), | |
) | |
); | |
$this->add( | |
array( | |
'type' => 'DoctrineORMModule\Form\Element\EntitySelect', | |
'name' => 'category', | |
'options' => array( | |
'label' => 'Category', | |
'object_manager' => $entityManager, | |
'target_class' => 'Blog\Entity\Category', | |
'property' => 'name' | |
), | |
'attributes' => array( | |
'required' => true, | |
) | |
) | |
); | |
$this->add( | |
array( | |
'type' => 'Zend\Form\Element\Checkbox', | |
'name' => 'state', | |
'options' => array( | |
'label' => 'State', | |
), | |
) | |
); | |
} | |
/** | |
* Should return an array specification compatible with | |
* {@link Zend\InputFilter\Factory::createInputFilter()}. | |
* | |
* @return array | |
*/ | |
public function getInputFilterSpecification() | |
{ | |
return array( | |
'date' => array( | |
'required' => true, | |
'filters' => array( | |
array('name' => 'StringTrim'), | |
array('name' => 'StripTags') | |
), | |
'properties' => array( | |
'required' => true | |
) | |
), | |
'content' => array( | |
'required' => true, | |
'filters' => array( | |
array('name' => 'StringTrim'), | |
), | |
'properties' => array( | |
'required' => true | |
) | |
), | |
'title' => array( | |
'required' => true, | |
'filters' => array( | |
array('name' => 'StringTrim'), | |
array('name' => 'StripTags') | |
), | |
'properties' => array( | |
'required' => true | |
) | |
), | |
'category' => array( | |
'required' => true, | |
'filters' => array( | |
array('name' => 'StringTrim'), | |
array('name' => 'StripTags') | |
), | |
'properties' => array( | |
'required' => true | |
) | |
), | |
'state' => array( | |
'required' => true, | |
'properties' => array( | |
'required' => true | |
) | |
) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment