Skip to content

Instantly share code, notes, and snippets.

@vittore
Created January 15, 2015 06:51
Show Gist options
  • Save vittore/29b4947cd0d1e5396684 to your computer and use it in GitHub Desktop.
Save vittore/29b4947cd0d1e5396684 to your computer and use it in GitHub Desktop.
<?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