Skip to content

Instantly share code, notes, and snippets.

@awartoft
Created July 31, 2012 07:47
Show Gist options
  • Save awartoft/3214632 to your computer and use it in GitHub Desktop.
Save awartoft/3214632 to your computer and use it in GitHub Desktop.
<?php
/**
* @author Jonas Eriksson <[email protected]>
* @author Antoine Hedgecock <[email protected]>
*/
/**
*
*/
namespace Article\Form\Admin;
use Zend\ServiceManager\ServiceManager,
Zend\ServiceManager\ServiceManagerAwareInterface,
Zend\Form\Form,
Zend\InputFilter\InputFilter;
class Create extends Form implements ServiceManagerAwareInterface
{
public function __construct()
{
parent::__construct('article_create');
$this->setAttribute('method', 'post')
->setHydrator(new \Zend\Stdlib\Hydrator\ClassMethods())
->setInputFilter(new InputFilter());
$this->add(array(
'type' => 'Article\Form\Fieldsets\ArticleFieldset',
'options' => array(
'use_as_base_fieldset' => true
)
));
}
/**
* @param ServiceManager $serviceManager
*/
public function setServiceManager(ServiceManager $serviceManager)
{
// Set the hydrator from the service manager
$this->get('article')
->setHydrator($serviceManager->get('MCN.object.hydrator'));
// Updated the company input filter
$this->getInputFilter()
->get('article')
->get('company')
->get('id')
->setAllowEmpty(true);
// fetch the categories
$categories = $serviceManager->get('article_service_category')
->fetchAll(array('sort' => array('name' => 'ASC')));
// Iterate them into something useful for the form element
foreach($categories as $category) {
$values[$category['id']] = $category['name'];
}
// Get the fieldset and set the categories..
$this->get('article')
->get('category')
->get('id')
->setAttribute('options', $values);
$this->get('article')
->get('author')
->get('id')
->setAttribute('value', $serviceManager->get('user_service_auth')->getIdentity()->getId());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment