Created
January 15, 2015 06:51
-
-
Save vittore/29b4947cd0d1e5396684 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 MyBundle\Admin; | |
use Sonata\AdminBundle\Admin\Admin; | |
use Sonata\AdminBundle\Datagrid\ListMapper; | |
use Sonata\AdminBundle\Datagrid\DatagridMapper; | |
use Sonata\AdminBundle\Form\FormMapper; | |
use Sonata\AdminBundle\Show\ShowMapper; | |
use FOS\UserBundle\Model\UserManagerInterface; | |
use Sonata\AdminBundle\Route\RouteCollection; | |
use Symfony\Component\HttpFoundation\File\UploadedFile; | |
class EventAdmin extends Admin | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
protected function configureShowFields(ShowMapper $showMapper) | |
{ | |
$showMapper | |
->add('name') | |
->add('location'); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
protected function configureFormFields(FormMapper $formMapper) | |
{ | |
$formMapper | |
->add('name') | |
->add('location') | |
->add('logo', 'file', array('label' => 'Image file', 'required' => false)); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
protected function configureDatagridFilters(DatagridMapper $filterMapper) | |
{ | |
$filterMapper | |
->add('onStage') | |
->add('name') | |
->add('location'); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
protected function configureListFields(ListMapper $listMapper) | |
{ | |
$listMapper | |
->addIdentifier('onStage') | |
->addIdentifier('name') | |
->addIdentifier('location'); | |
} | |
public function prePersist($event) | |
{ | |
$this->saveFile($event); | |
} | |
public function preUpdate($event) | |
{ | |
$this->saveFile($event); | |
} | |
public function saveFile($event) | |
{ | |
$basepath = $this->getRequest()->getBasePath(); | |
$event->upload($basepath); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment