14
14
use Sonata \AdminBundle \Datagrid \DatagridMapper ;
15
15
use Sonata \AdminBundle \Datagrid \ListMapper ;
16
16
use Sonata \AdminBundle \Form \FormMapper ;
17
- use Sonata \DoctrinePHPCRAdminBundle \Admin \Admin ;
18
- use Symfony \Cmf \Bundle \ContentBundle \Doctrine \Phpcr \Form \Type \StaticContentType ;
19
17
use Symfony \Cmf \Bundle \ContentBundle \Model \StaticContentBase ;
18
+ use Symfony \Cmf \Bundle \SonataPhpcrAdminIntegrationBundle \Admin \AbstractAdmin ;
19
+ use Symfony \Cmf \Bundle \TreeBrowserBundle \Form \Type \TreeSelectType ;
20
+ use Symfony \Component \Form \Extension \Core \Type \TextType ;
21
+ use Symfony \Component \Form \Extension \Core \Type \TextareaType ;
20
22
21
- class StaticContentAdmin extends Admin
23
+ class StaticContentAdmin extends AbstractAdmin
22
24
{
23
25
protected $ translationDomain = 'CmfSonataPhpcrAdminIntegrationBundle ' ;
24
26
@@ -37,25 +39,31 @@ protected function configureListFields(ListMapper $listMapper)
37
39
38
40
protected function configureFormFields (FormMapper $ formMapper )
39
41
{
40
- $ builder = $ formMapper ->getFormBuilder ()->getFormFactory ()->createBuilder (StaticContentType::class, null , [
41
- 'readonly_parent_document ' => (bool ) $ this ->id ($ this ->getSubject ()),
42
- 'label_format ' => 'form.label_%name% ' ,
43
- 'translation_domain ' => 'CmfSonataPhpcrAdminIntegrationBundle ' ,
44
- ]);
45
-
42
+ $ editView = (bool ) $ this ->id ($ this ->getSubject ());
46
43
$ formMapper
47
44
->tab ('form.tab_general ' )
48
45
->with ('form.group_content ' , ['class ' => 'col-md-9 ' ])
49
- ->add ($ builder -> get ( 'title ' ) )
50
- ->add ($ builder -> get ( 'body ' ) )
46
+ ->add ('title ' , TextType::class )
47
+ ->add ('body ' , TextareaType::class )
51
48
->end ()
52
49
53
50
->with ('form.group_location ' , ['class ' => 'col-md-3 ' ])
54
- ->add ($ builder ->get ('parentDocument ' ))
55
- ->add ($ builder ->get ('name ' ))
51
+ ->ifTrue ($ editView )
52
+ ->add ('parentDocument ' , TextType::class, ['disabled ' => true ])
53
+ ->ifEnd ()
54
+ ->ifFalse ($ editView )
55
+ ->add ('parentDocument ' , TreeSelectType::class, [
56
+ 'widget ' => 'browser ' ,
57
+ 'root_node ' => $ this ->getRootPath (),
58
+ ])
59
+ ->ifend ()
60
+
61
+ ->add ('name ' , TextType::class)
56
62
->end ()
57
63
->end ()
58
64
;
65
+
66
+ $ this ->addTransformerToField ($ formMapper ->getFormBuilder (), 'parentDocument ' );
59
67
}
60
68
61
69
protected function configureDatagridFilters (DatagridMapper $ datagridMapper )
0 commit comments