This repo is created for the SplendidBear Websites' portfolio. https://www.splendidbear.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

138 lines
3.5 KiB

<?php
namespace App\Admin;
use App\Entity\Project;
use Pix\SortableBehaviorBundle\Services\PositionHandler;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Form\Type\ModelListType;
use Sonata\AdminBundle\Route\RouteCollection;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
/**
* Class ProjectAdmin
*
* @package App\Admin
* @author system7 <https://www.laszlolang.com>
*/
class ProjectAdmin extends AbstractAdmin
{
/** {@inheritdoc} */
protected $baseRouteName = 'project';
/** {@inheritdoc} */
protected $baseRoutePattern = 'project';
protected $datagridValues = array(
'_page' => 1,
'_sort_order' => 'ASC',
'_sort_by' => 'position',
);
/**
* {@inheritdoc}
*/
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->with('Data', array('class' => 'col-md-6'))
->add(
'title',
null,
array(
'required' => true,
)
)
->add(
'codeName',
null,
array(
'required' => true,
)
)
->add('position',
HiddenType::class,
array(
'attr' => array(
'hidden' => true,
),
))
->add(
'media',
ModelListType::class,
array(
'required' => false,
'btn_list' => false,
),
array(
'link_parameters' => array(
'context' => 'project'
)
))
->end();
}
/**
* {@inheritdoc}
*/
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
->add('title');
}
/**
* {@inheritdoc}
*/
protected function configureListFields(ListMapper $listMapper)
{
/** Disable mosaic view */
unset($this->listModes['mosaic']);
$listMapper
->add('media')
->add('title')
->add('codeName')
->add(
'_action',
null,
array(
'actions' => array(
'edit' => array(),
'move' => array(
'template' => '@PixSortableBehavior/Default/_sort.html.twig'
),
// 'move' => array(
// 'template' => '@PixSortableBehavior/Default/_sort_drag_drop.html.twig',
// 'enable_top_bottom_buttons' => true,
// ),
),
)
);
}
/**
* {@inheritdoc}
*/
protected function configureRoutes(RouteCollection $collection)
{
$collection->add('move', $this->getRouterIdParameter() . '/move/{position}');
parent::configureRoutes($collection);
}
/**
* @param Project $object
*
* @return string
*/
public function toString($object)
{
return $object instanceof Project
? $object->getTitle()
: 'Project';
}
}