Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Commit

Permalink
replace them all
Browse files Browse the repository at this point in the history
add data transformers on abstract way

use current form builder

fix menu block admin

fix menu admin problem

use parent service definition

use current form builder

fix menu block admin

fix menu admin problem

use parent service definition

Apply fixes from StyleCI
  • Loading branch information
ElectricMaxxx committed Jan 2, 2017
1 parent 38da164 commit a9f162e
Show file tree
Hide file tree
Showing 19 changed files with 139 additions and 68 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
37 changes: 37 additions & 0 deletions src/Admin/AbstractAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Symfony\Cmf\Bundle\SonataAdminIntegrationBundle\Admin;

use Doctrine\Bundle\PHPCRBundle\Form\DataTransformer\DocumentToPathTransformer;
use Sonata\DoctrinePHPCRAdminBundle\Admin\Admin;
use Symfony\Bridge\Doctrine\ManagerRegistry;
use Symfony\Component\Form\FormBuilder;

/**
* @author Maximilian Berghoff <[email protected]>
*/
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())
));
}
}
14 changes: 8 additions & 6 deletions src/Admin/Block/AbstractBlockAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
*/
abstract class AbstractBlockAdmin extends Admin
abstract class AbstractBlockAdmin extends AbstractAdmin
{
/**
* @var string
Expand All @@ -31,7 +31,7 @@ abstract class AbstractBlockAdmin extends Admin
*/
public function getExportFormats()
{
return array();
return [];
}

/**
Expand All @@ -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');
}
}
8 changes: 5 additions & 3 deletions src/Admin/Block/MenuBlockAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Admin/Block/ReferenceBlockAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions src/Admin/Menu/AbstractMenuNodeAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -74,7 +74,7 @@ protected function configureShowFields(ShowMapper $showMapper)

public function getExportFormats()
{
return array();
return [];
}

public function setContentRoot($contentRoot)
Expand Down
28 changes: 15 additions & 13 deletions src/Admin/Menu/MenuNodeAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

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;
use Symfony\Cmf\Bundle\MenuBundle\Model\MenuNode;
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;

Expand All @@ -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()) {
Expand All @@ -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');
}
}

Expand Down
15 changes: 8 additions & 7 deletions src/Admin/Routing/RedirectRouteAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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()
Expand All @@ -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)
Expand Down
19 changes: 12 additions & 7 deletions src/Admin/Routing/RouteAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions src/Resources/config/block-imagine.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

<service
id="cmf_sonata_admin_integration.block.imagine.slideshow_admin"
class="Symfony\Cmf\Bundle\SonataAdminIntegrationBundle\Admin\Block\Imagine\SlideshowBlockAdmin">
class="Symfony\Cmf\Bundle\SonataAdminIntegrationBundle\Admin\Block\Imagine\SlideshowBlockAdmin"
parent="cmf_sonata_admin_integration.abstract_admin">
<tag
name="sonata.admin"
manager_type="doctrine_phpcr"
Expand All @@ -35,7 +36,8 @@

<service
id="cmf_sonata_admin_integration.block.imagine.imagine_admin"
class="Symfony\Cmf\Bundle\SonataAdminIntegrationBundle\Admin\Block\Imagine\ImagineBlockAdmin">
class="Symfony\Cmf\Bundle\SonataAdminIntegrationBundle\Admin\Block\Imagine\ImagineBlockAdmin"
parent="cmf_sonata_admin_integration.abstract_admin">
<tag
name="sonata.admin"
manager_type="doctrine_phpcr"
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/config/block-menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
<services>
<service
id="cmf_sonata_admin_integration.block.menu_admin"
class="Symfony\Cmf\Bundle\SonataAdminIntegrationBundle\Admin\Block\MenuBlockAdmin">
class="Symfony\Cmf\Bundle\SonataAdminIntegrationBundle\Admin\Block\MenuBlockAdmin"
parent="cmf_sonata_admin_integration.abstract_admin">
<tag
name="sonata.admin"
manager_type="doctrine_phpcr"
Expand Down
Loading

0 comments on commit a9f162e

Please sign in to comment.