/
NewsAdmin.php
37 lines (31 loc) · 1.21 KB
/
NewsAdmin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
namespace Acme\DemoBundle\Admin;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
class NewsAdmin extends Admin {
protected function configureFormFields(FormMapper $formMapper) {
$formMapper
->add('newsDate', 'date', [
'empty_value' => ['month' => 'Month', 'day' => 'Day', 'year' => 'Year'],
'format' => 'ddMMMMyyyy'
])
->add('active', null, array('required' => false));
}
protected function configureListFields(ListMapper $listMapper) {
$listMapper
->add('id', null, array('sortable' => false))
->addIdentifier('title', 'string', array('template' => 'EoneSonataCustomizationBundle:CRUD:list_translatable.html.twig'))
->add('newsDate')
->add('active', null, array('sortable' => false, 'editable' => true))
;
}
public function getNewInstance() {
$instance = parent::getNewInstance();
$instance->setActive(true);
$now = new \DateTime();
$now->setTime(0, 0, 0);
$instance->setNewsDate($now);
return $instance;
}
}