forked from symfony-cmf/blog-bundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostAdmin.php
75 lines (62 loc) · 2.05 KB
/
PostAdmin.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/*
* This file is part of the Symfony CMF package.
*
* (c) 2011-2014 Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Cmf\Bundle\BlogBundle\Admin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Validator\ErrorElement;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\DoctrinePHPCRAdminBundle\Admin\Admin;
use Symfony\Cmf\Bundle\BlogBundle\Form\DataTransformer\CsvToArrayTransformer;
/**
* Post Admin
*
* @author Daniel Leech <[email protected]>
*/
class PostAdmin extends Admin
{
protected $translationDomain = 'CmfBlogBundle';
protected function configureFormFields(FormMapper $mapper)
{
// @todo: I think this would be better as a service,
// but I don't know how integrate the form
// AND have all the Sonata magic from the
// FormMapper->add method.
// $csvToArrayTransformer = new CsvToArrayTransformer;
$mapper
->with('dashboard.label_post')
->add('title')
->add('date', 'datetime', array(
'widget' => 'single_text',
))
->add('body', 'textarea')
->add('blog', 'phpcr_document', array(
'class' => 'Symfony\Cmf\Bundle\BlogBundle\Document\Blog',
))
->end()
;
//$tags = $mapper->create('tags', 'text')
// ->addModelTransformer($csvToArrayTransformer);
// $mapper->add($tags);
}
protected function configureDatagridFilters(DatagridMapper $dm)
{
$dm->add('title', 'doctrine_phpcr_string');
}
protected function configureListFields(ListMapper $dm)
{
$dm->add('blog');
$dm->add('date', 'datetime');
$dm->addIdentifier('title');
}
public function validate(ErrorElement $ee, $obj)
{
$ee->with('title')->assertNotBlank()->end();
}
}