Skip to content

Instantly share code, notes, and snippets.

@kix
Created January 22, 2015 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kix/cc256f0c8b4169e56cfb to your computer and use it in GitHub Desktop.
Save kix/cc256f0c8b4169e56cfb to your computer and use it in GitHub Desktop.
<?php
namespace AppBundle\Admin;
use \Symfony\Component\DependencyInjection\ContainerInterface;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Route\RouteCollection;
use \Pix\SortableBehaviorBundle\Services\PositionHandler;
class ArticleAdmin extends Admin
{
public $last_position = 0;
protected $baseRouteName = 'articles';
protected $baseRoutePattern = 'articles';
private $container;
private $positionService;
protected $datagridValues = array(
'_page' => 1,
'_sort_order' => 'ASC',
'_sort_by' => 'position',
);
public function setContainer(ContainerInterface $container)
{
$this->container = $container;
}
public function setPositionService(PositionHandler $positionHandler)
{
$this->positionService = $positionHandler;
}
protected function configureRoutes(RouteCollection $collection)
{
parent::configureRoutes($collection);
$collection->remove('batch');
$collection->add('move', $this->getRouterIdParameter() . '/move/{position}');
}
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->with('Страница')
->add('title', 'text', array(
'label' => 'Заголовок страницы',
))
->add('isPublished', 'checkbox', array(
'label' => 'Опубликовать',
'required' => false,
))
->add('content', 'ckeditor', array(
'label' => 'Текст',
))
->end()
->with('SEO-настройки')
->add('description', 'text', array(
'label' => 'Тег description',
'required' => false,
))
->add('keywords', 'text', array(
'label' => 'Тег keywords',
'required' => false,
))
->add('slug', 'text', array(
'label' => 'Алиас',
))
->end()
;
}
protected function configureListFields(ListMapper $listMapper)
{
$this->last_position = $this->positionService->getLastPosition($this->getRoot()->getClass());
$listMapper
->addIdentifier('title', null, array(
'label' => 'Название',
))
->add('isPublished', null, array(
'label' => 'Опубликована',
))
->add('slug', null, array(
'label' => 'Адрес',
))
->add('_action', 'actions', array(
'label' => 'Порядок',
'actions' => array(
'move' => array(
'template' => 'PixSortableBehaviorBundle:Default:_sort.html.twig',
),
)
))
;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment