diff --git a/composer.json b/composer.json index c92e374..46cc359 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,8 @@ "php": "^5.5.6|^7.0", "symfony/framework-bundle": "^2.8|^3.0", "sonata-project/doctrine-phpcr-admin-bundle": "^2.0", - "sonata-project/admin-bundle": "^3.6.0" + "sonata-project/admin-bundle": "^3.6.0", + "symfony-cmf/tree-browser-bundle": "^2.0" }, "require-dev": { "symfony-cmf/testing": "^2.0", diff --git a/src/Admin/AbstractAdmin.php b/src/Admin/AbstractAdmin.php new file mode 100644 index 0000000..bc17693 --- /dev/null +++ b/src/Admin/AbstractAdmin.php @@ -0,0 +1,37 @@ + + */ +class AbstractAdmin extends Admin +{ + /** + * @var ManagerRegistry + */ + private $managerRegistry; + + public function setManagerRegistry(ManagerRegistry $managerRegistry) + { + $this->managerRegistry = $managerRegistry; + } + + /** + * Will add a the phpcr data transformer to a specific field. + * + * @param FormBuilder $formBuilder + * @param $fieldName + */ + public function addTransformerToField(FormBuilder $formBuilder, $fieldName) + { + $formBuilder->get($fieldName)->addModelTransformer(new DocumentToPathTransformer( + $this->managerRegistry->getManagerForClass($this->getClass()) + )); + } +} diff --git a/src/Admin/Block/AbstractBlockAdmin.php b/src/Admin/Block/AbstractBlockAdmin.php index 44d8fa2..531873d 100644 --- a/src/Admin/Block/AbstractBlockAdmin.php +++ b/src/Admin/Block/AbstractBlockAdmin.php @@ -12,14 +12,14 @@ namespace Symfony\Cmf\Bundle\SonataAdminIntegrationBundle\Admin\Block; use Sonata\AdminBundle\Form\FormMapper; -use Sonata\DoctrinePHPCRAdminBundle\Admin\Admin; -use Sonata\DoctrinePHPCRAdminBundle\Form\Type\TreeModelType; +use Symfony\Cmf\Bundle\SonataAdminIntegrationBundle\Admin\AbstractAdmin; +use Symfony\Cmf\Bundle\TreeBrowserBundle\Form\Type\TreeSelectType; use Symfony\Component\Form\Extension\Core\Type\TextType; /** * @author Nicolas Bastien */ -abstract class AbstractBlockAdmin extends Admin +abstract class AbstractBlockAdmin extends AbstractAdmin { /** * @var string @@ -31,7 +31,7 @@ abstract class AbstractBlockAdmin extends Admin */ public function getExportFormats() { - return array(); + return []; } /** @@ -44,12 +44,14 @@ protected function configureFormFields(FormMapper $formMapper) ->with('form.group_location', ['class' => 'col-md-3']) ->add( 'parentDocument', - TreeModelType::class, - ['root_node' => $this->getRootPath(), 'choice_list' => array(), 'select_root_node' => true] + TreeSelectType::class, + ['root_node' => $this->getRootPath(), 'widget' => 'browser'] ) ->add('name', TextType::class) ->end() ->end() ; + + $this->addTransformerToField($formMapper->getFormBuilder(), 'parentDocument'); } } diff --git a/src/Admin/Block/MenuBlockAdmin.php b/src/Admin/Block/MenuBlockAdmin.php index 4eddfa8..c47a1df 100644 --- a/src/Admin/Block/MenuBlockAdmin.php +++ b/src/Admin/Block/MenuBlockAdmin.php @@ -14,7 +14,7 @@ use Sonata\AdminBundle\Datagrid\DatagridMapper; use Sonata\AdminBundle\Datagrid\ListMapper; use Sonata\AdminBundle\Form\FormMapper; -use Sonata\DoctrinePHPCRAdminBundle\Form\Type\TreeModelType; +use Symfony\Cmf\Bundle\TreeBrowserBundle\Form\Type\TreeSelectType; /** * Sonata admin for the MenuBlock. Allows to select the target menu node from @@ -47,12 +47,14 @@ protected function configureFormFields(FormMapper $formMapper) ->with('form.group_block', ['class' => 'col-md-9']) ->add( 'menuNode', - TreeModelType::class, - ['choice_list' => [], 'required' => true, 'root_node' => $this->menuPath] + TreeSelectType::class, + ['root_node' => $this->menuPath, 'widget' => 'browser', 'required' => true] ) ->end() ->end() ; + + $this->addTransformerToField($formMapper->getFormBuilder(), 'menuNode'); } /** diff --git a/src/Admin/Block/ReferenceBlockAdmin.php b/src/Admin/Block/ReferenceBlockAdmin.php index 438d557..621e568 100644 --- a/src/Admin/Block/ReferenceBlockAdmin.php +++ b/src/Admin/Block/ReferenceBlockAdmin.php @@ -14,7 +14,7 @@ use Sonata\AdminBundle\Datagrid\DatagridMapper; use Sonata\AdminBundle\Datagrid\ListMapper; use Sonata\AdminBundle\Form\FormMapper; -use Sonata\DoctrinePHPCRAdminBundle\Form\Type\TreeModelType; +use Symfony\Cmf\Bundle\TreeBrowserBundle\Form\Type\TreeSelectType; /** * @author Lukas Kahwe Smith @@ -44,8 +44,8 @@ protected function configureFormFields(FormMapper $formMapper) ->with('form.group_block', ['class' => 'col-md-9']) ->add( 'referencedBlock', - TreeModelType::class, - ['choice_list' => [], 'required' => false, 'root_node' => $this->getRootPath()] + TreeSelectType::class, + ['root_node' => $this->getRootPath(), 'widget' => 'browser', 'required' => false] ) ->end() ->end() diff --git a/src/Admin/Menu/AbstractMenuNodeAdmin.php b/src/Admin/Menu/AbstractMenuNodeAdmin.php index e2feaf4..b142a9f 100644 --- a/src/Admin/Menu/AbstractMenuNodeAdmin.php +++ b/src/Admin/Menu/AbstractMenuNodeAdmin.php @@ -14,14 +14,14 @@ use Sonata\AdminBundle\Datagrid\ListMapper; use Sonata\AdminBundle\Form\FormMapper; use Sonata\AdminBundle\Show\ShowMapper; -use Sonata\DoctrinePHPCRAdminBundle\Admin\Admin; +use Symfony\Cmf\Bundle\SonataAdminIntegrationBundle\Admin\AbstractAdmin; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Cmf\Bundle\MenuBundle\Model\MenuNodeBase; /** * Common base admin for Menu and MenuNode. */ -abstract class AbstractMenuNodeAdmin extends Admin +abstract class AbstractMenuNodeAdmin extends AbstractAdmin { /** * @var string @@ -74,7 +74,7 @@ protected function configureShowFields(ShowMapper $showMapper) public function getExportFormats() { - return array(); + return []; } public function setContentRoot($contentRoot) diff --git a/src/Admin/Menu/MenuNodeAdmin.php b/src/Admin/Menu/MenuNodeAdmin.php index 628d950..149dd40 100644 --- a/src/Admin/Menu/MenuNodeAdmin.php +++ b/src/Admin/Menu/MenuNodeAdmin.php @@ -11,6 +11,7 @@ namespace Symfony\Cmf\Bundle\SonataAdminIntegrationBundle\Admin\Menu; +use Symfony\Cmf\Bundle\TreeBrowserBundle\Form\Type\TreeSelectType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; @@ -18,7 +19,6 @@ use Sonata\AdminBundle\Datagrid\ListMapper; use Sonata\AdminBundle\Form\FormMapper; use Sonata\DoctrinePHPCRAdminBundle\Form\Type\ChoiceFieldMaskType; -use Sonata\DoctrinePHPCRAdminBundle\Form\Type\TreeModelType; use Knp\Menu\ItemInterface as MenuItemInterface; use Doctrine\Common\Util\ClassUtils; @@ -44,15 +44,17 @@ protected function configureFormFields(FormMapper $formMapper) $formMapper ->tab('form.tab_general') ->with('form.group_location', ['class' => 'col-sm-3']) - ->add('parentDocument', TreeModelType::class, array( - 'root_node' => $this->menuRoot, - 'choice_list' => array(), - 'select_root_node' => true, - )) + ->add( + 'parentDocument', + TreeSelectType::class, + ['root_node' => $this->menuRoot, 'widget' => 'browser'] + ) ->end() ->end() ; + $this->addTransformerToField($formMapper->getFormBuilder(), 'parentDocument'); + parent::configureFormFields($formMapper); if (null === $this->getParentFieldDescription()) { @@ -69,22 +71,22 @@ protected function configureFormFields(FormMapper $formMapper) 'map' => array( 'route' => array('link'), 'uri' => array('link'), - 'content' => array('content', TreeModelType::class), + 'content' => array('content', TreeSelectType::class), ), 'placeholder' => 'auto', 'required' => false, )) ->add('link', TextType::class, array('required' => false, 'mapped' => false)) - ->add('content', TreeModelType::class, - array( - 'root_node' => $this->contentRoot, - 'choice_list' => array(), - 'required' => false, - ) + ->add( + 'content', + TreeSelectType::class, + ['root_node' => $this->contentRoot, 'widget' => 'browser', 'required' => false] ) ->end() ->end() ; + + $this->addTransformerToField($formMapper->getFormBuilder(), 'content'); } } diff --git a/src/Admin/Routing/RedirectRouteAdmin.php b/src/Admin/Routing/RedirectRouteAdmin.php index 0d950b7..cac4609 100644 --- a/src/Admin/Routing/RedirectRouteAdmin.php +++ b/src/Admin/Routing/RedirectRouteAdmin.php @@ -14,12 +14,12 @@ use Sonata\AdminBundle\Datagrid\DatagridMapper; use Sonata\AdminBundle\Datagrid\ListMapper; use Sonata\AdminBundle\Form\FormMapper; -use Sonata\DoctrinePHPCRAdminBundle\Admin\Admin; -use Sonata\DoctrinePHPCRAdminBundle\Form\Type\TreeModelType; +use Symfony\Cmf\Bundle\SonataAdminIntegrationBundle\Admin\AbstractAdmin; +use Symfony\Cmf\Bundle\TreeBrowserBundle\Form\Type\TreeSelectType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Cmf\Bundle\RoutingBundle\Model\Route; -class RedirectRouteAdmin extends Admin +class RedirectRouteAdmin extends AbstractAdmin { protected $translationDomain = 'CmfSonataAdminIntegrationBundle'; @@ -41,8 +41,8 @@ protected function configureFormFields(FormMapper $formMapper) ->with('form.group_location', ['class' => 'col-md-3']) ->add( 'parentDocument', - TreeModelType::class, - ['choice_list' => [], 'select_root_node' => true, 'root_node' => $this->routeRoot] + TreeSelectType::class, + ['root_node' => $this->routeRoot, 'widget' => 'browser'] ) ->add('name', TextType::class) ->end() @@ -52,11 +52,12 @@ protected function configureFormFields(FormMapper $formMapper) ->add('uri', TextType::class, ['required' => false]) ->add( 'routeTarget', - TreeModelType::class, - ['choice_list' => [], 'required' => false, 'root_node' => $this->routeRoot] + TreeSelectType::class, + ['root_node' => $this->routeRoot, 'widget' => 'browser', 'required' => false] ) ->end() ; + $this->addTransformerToField($formMapper->getFormBuilder(), 'parentDocument'); } protected function configureDatagridFilters(DatagridMapper $datagridMapper) diff --git a/src/Admin/Routing/RouteAdmin.php b/src/Admin/Routing/RouteAdmin.php index 84dd128..be58560 100644 --- a/src/Admin/Routing/RouteAdmin.php +++ b/src/Admin/Routing/RouteAdmin.php @@ -15,15 +15,15 @@ use Sonata\AdminBundle\Datagrid\ListMapper; use Sonata\AdminBundle\Form\FormMapper; use Sonata\CoreBundle\Form\Type\ImmutableArrayType; -use Sonata\DoctrinePHPCRAdminBundle\Admin\Admin; -use Sonata\DoctrinePHPCRAdminBundle\Form\Type\TreeModelType; +use Symfony\Cmf\Bundle\SonataAdminIntegrationBundle\Admin\AbstractAdmin; +use Symfony\Cmf\Bundle\TreeBrowserBundle\Form\Type\TreeSelectType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Cmf\Bundle\RoutingBundle\Model\Route; use Symfony\Cmf\Bundle\RoutingBundle\Form\Type\RouteTypeType; use PHPCR\Util\PathHelper; -class RouteAdmin extends Admin +class RouteAdmin extends AbstractAdmin { protected $translationDomain = 'CmfSonataAdminIntegrationBundle'; @@ -53,8 +53,8 @@ protected function configureFormFields(FormMapper $formMapper) ->with('form.group_location', ['class' => 'col-md-3']) ->add( 'parentDocument', - TreeModelType::class, - ['choice_list' => [], 'select_root_node' => true, 'root_node' => $this->routeRoot] + TreeSelectType::class, + ['root_node' => $this->routeRoot, 'widget' => 'browser'] ) ->add('name', TextType::class) ->end() // group location @@ -63,8 +63,8 @@ protected function configureFormFields(FormMapper $formMapper) ->with('form.group_target', ['class' => 'col-md-9']) ->add( 'content', - TreeModelType::class, - ['choice_list' => [], 'required' => false, 'root_node' => $this->contentRoot] + TreeSelectType::class, + ['root_node' => $this->routeRoot, 'widget' => 'browser', 'required' => false] ) ->end() // group general ->end() // tab general @@ -95,6 +95,11 @@ protected function configureFormFields(FormMapper $formMapper) ->ifEnd() ->end(); // tab general/routing + + $this->addTransformerToField($formMapper->getFormBuilder(), 'parentDocument'); + if (null === $this->getParentFieldDescription()) { + $this->addTransformerToField($formMapper->getFormBuilder(), 'content'); + } } protected function configureDatagridFilters(DatagridMapper $datagridMapper) diff --git a/src/DependencyInjection/CmfSonataAdminIntegrationExtension.php b/src/DependencyInjection/CmfSonataAdminIntegrationExtension.php index 1346fb3..d0a7367 100644 --- a/src/DependencyInjection/CmfSonataAdminIntegrationExtension.php +++ b/src/DependencyInjection/CmfSonataAdminIntegrationExtension.php @@ -55,6 +55,8 @@ public function load(array $configs, ContainerBuilder $container) $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $this->loadBundles($config['bundles'], $loader, $container); + + $loader->load('main-phpcr.xml'); } private function loadBundles(array $config, XmlFileLoader $loader, ContainerBuilder $container) diff --git a/src/Resources/config/block-imagine.xml b/src/Resources/config/block-imagine.xml index b926b41..9982ffc 100644 --- a/src/Resources/config/block-imagine.xml +++ b/src/Resources/config/block-imagine.xml @@ -8,7 +8,8 @@ + class="Symfony\Cmf\Bundle\SonataAdminIntegrationBundle\Admin\Block\Imagine\SlideshowBlockAdmin" + parent="cmf_sonata_admin_integration.abstract_admin"> + class="Symfony\Cmf\Bundle\SonataAdminIntegrationBundle\Admin\Block\Imagine\ImagineBlockAdmin" + parent="cmf_sonata_admin_integration.abstract_admin"> + class="Symfony\Cmf\Bundle\SonataAdminIntegrationBundle\Admin\Block\MenuBlockAdmin" + parent="cmf_sonata_admin_integration.abstract_admin"> + class="Symfony\Cmf\Bundle\SonataAdminIntegrationBundle\Admin\Block\SimpleBlockAdmin" + parent="cmf_sonata_admin_integration.abstract_admin"> + class="Symfony\Cmf\Bundle\SonataAdminIntegrationBundle\Admin\Block\ActionBlockAdmin" + parent="cmf_sonata_admin_integration.abstract_admin"> + class="Symfony\Cmf\Bundle\SonataAdminIntegrationBundle\Admin\Block\ContainerBlockAdmin" + parent="cmf_sonata_admin_integration.abstract_admin"> + class="Symfony\Cmf\Bundle\SonataAdminIntegrationBundle\Admin\Block\ReferenceBlockAdmin" + parent="cmf_sonata_admin_integration.abstract_admin"> + class="Symfony\Cmf\Bundle\SonataAdminIntegrationBundle\Admin\Block\StringBlockAdmin" + parent="cmf_sonata_admin_integration.abstract_admin"> + + + + + + + + + + + + + diff --git a/src/Resources/config/menu.xml b/src/Resources/config/menu.xml index c1e4dad..95ddf4e 100644 --- a/src/Resources/config/menu.xml +++ b/src/Resources/config/menu.xml @@ -8,7 +8,8 @@ + class="Symfony\Cmf\Bundle\SonataAdminIntegrationBundle\Admin\Menu\MenuAdmin" + parent="cmf_sonata_admin_integration.abstract_admin"> + class="Symfony\Cmf\Bundle\SonataAdminIntegrationBundle\Admin\Menu\MenuNodeAdmin" + parent="cmf_sonata_admin_integration.abstract_admin"> + class="Symfony\Cmf\Bundle\SonataAdminIntegrationBundle\Admin\Routing\RouteAdmin" + parent="cmf_sonata_admin_integration.abstract_admin"> + class="Symfony\Cmf\Bundle\SonataAdminIntegrationBundle\Admin\Routing\RedirectRouteAdmin" + parent="cmf_sonata_admin_integration.abstract_admin"> addCollection($loader->import(__DIR__.'/routing.yml')); -$collection->addCollection($loader->import(__DIR__.'/tree_browser_'.$treeBrowserVersion.'.yml')); +$collection->addCollection($loader->import(__DIR__.'/tree_browser_2.x.yml')); return $collection; diff --git a/tests/Resources/app/config/tree_browser_1.x.yml b/tests/Resources/app/config/tree_browser_1.x.yml deleted file mode 100644 index ed4a4d6..0000000 --- a/tests/Resources/app/config/tree_browser_1.x.yml +++ /dev/null @@ -1,6 +0,0 @@ -cmf_tree: - resource: . - type: 'cmf_tree' - -fos_js_routing: - resource: '@FOSJsRoutingBundle/Resources/config/routing/routing.xml'