Skip to content

Commit

Permalink
Merge pull request sonata-project#339 from WouterJ/cleanup
Browse files Browse the repository at this point in the history
Cleanup for TreeBrowserBundle 2.0
  • Loading branch information
dbu committed May 7, 2015
2 parents d7e1af0 + 2226558 commit d6c232d
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 643 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

* **2015-05-06**: [BC break] Removed `Tree\PhpcrOdmTree`.
* **2015-05-06**: [BC break] Changed first argument of `Controller\TreeController` from `TreeInterface $tree` to `$repositoryName = 'default'`.
* **2015-05-06**: [BC break] The tree block template now only recieves a `repository_name`, `root_node` and `routing_defaults` variables.
* **2015-05-06**: Added `document_tree_repository` setting.
* **2015-05-06**: [BC break] Removed `Form\Type\TreeModelType#setTree()` method and `$tree` property.

1.2.0
-----

Expand Down
26 changes: 12 additions & 14 deletions Controller/TreeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Cmf\Bundle\TreeBrowserBundle\Tree\TreeInterface;

/**
* A controller to render the tree block
*/
class TreeController extends Controller
{
/**
* @var TreeInterface
* @var string
*/
private $tree;
private $repositoryName;

/**
* @var string
Expand All @@ -42,14 +41,14 @@ class TreeController extends Controller
private $confirmMove = false;

/**
* @param TreeInterface $tree
* @param string $template
* @param array $defaults
* @param string $repositoryName
* @param string $template
* @param array $defaults
* @param boolean $confirmMove
*/
public function __construct(TreeInterface $tree, $template = null, array $defaults = array(), $confirmMove = false)
public function __construct($repositoryName = 'default', $template = null, array $defaults = array(), $confirmMove = false)
{
$this->tree = $tree;
$this->repositoryName = $repositoryName;
if ($template) {
$this->template = $template;
}
Expand All @@ -76,14 +75,13 @@ public function treeAction(Request $request)
$selected = $request->attributes->get('selected') ?: $root;

return $this->render($this->template, array(
'tree' => $this->tree,
'repository_name' => $this->repositoryName,
'root_node' => $root,
'selected_node' => $selected,
'routing_defaults' => $this->defaults,
'confirm_move' => $this->confirmMove,
'create_in_overlay' => $createInOverlay ? $createInOverlay : false,
'edit_in_overlay' => $editInOverlay ? $editInOverlay : false,
'delete_in_overlay' => $deleteInOverlay ? $deleteInOverlay : false,
//'confirm_move' => $this->confirmMove,
//'create_in_overlay' => $createInOverlay ? $createInOverlay : false,
//'edit_in_overlay' => $editInOverlay ? $editInOverlay : false,
//'delete_in_overlay' => $deleteInOverlay ? $deleteInOverlay : false,
));
}
}
2 changes: 2 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public function getConfigTreeBuilder()
->end()
->end()

->scalarNode('document_tree_repository')->defaultValue('default')->end()

->arrayNode('document_tree_defaults')
->prototype('scalar')->end()
->end()
Expand Down
9 changes: 6 additions & 3 deletions DependencyInjection/SonataDoctrinePHPCRAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,16 @@ public function load(array $configs, ContainerBuilder $container)
*/
private function loadTreeTypes($config, ContainerBuilder $container)
{
$options = $config['document_tree_options'];
$container->setParameter('sonata_admin_doctrine_phpcr.tree_block.defaults', $config['document_tree_defaults']);
$container->setParameter('sonata_admin_doctrine_phpcr.tree_block.repository_name', $config['document_tree_repository']);

$options = $config['document_tree_options'];
$container->setParameter('sonata_admin_doctrine_phpcr.tree_confirm_move', $options['confirm_move']);

unset($options['confirm_move']);

$container->getDefinition('sonata.admin.doctrine_phpcr.phpcr_odm_tree')
->replaceArgument(5, $this->processDocumentTreeConfig($config['document_tree']));
$container->getDefinition('sonata.admin.doctrine_phpcr.phpcr_odm_tree')
->replaceArgument(5, $this->processDocumentTreeConfig($config['document_tree']))
->replaceArgument(6, $options);
}

Expand Down
6 changes: 3 additions & 3 deletions Form/Type/TreeManagerType.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class TreeManagerType extends AbstractType
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['root'] = $options['root'];
$view->vars['create_in_overlay'] = $options['create_in_overlay'];
$view->vars['edit_in_overlay'] = $options['edit_in_overlay'];
$view->vars['delete_in_overlay'] = $options['delete_in_overlay'];
//$view->vars['create_in_overlay'] = $options['create_in_overlay'];
//$view->vars['edit_in_overlay'] = $options['edit_in_overlay'];
//$view->vars['delete_in_overlay'] = $options['delete_in_overlay'];
parent::buildView($view, $form, $options);
}

Expand Down
15 changes: 0 additions & 15 deletions Form/Type/TreeModelType.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ class TreeModelType extends AbstractType
*/
protected $defaults = array();

/**
* @var TreeInterface
*/
protected $tree;

/**
* @param array $defaults
*/
Expand All @@ -44,14 +39,6 @@ public function setDefaults(array $defaults)
$this->defaults = $defaults;
}

/**
* @param TreeInterface $tree
*/
public function setTree(TreeInterface $tree)
{
$this->tree = $tree;
}

/**
* {@inheritDoc}
*/
Expand All @@ -68,8 +55,6 @@ public function buildForm(FormBuilderInterface $builder, array $options)
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
parent::buildView($view, $form, $options);
$view->vars['tree'] = $this->tree;
$view->vars['root_node'] = $form->getConfig()->getAttribute('root_node');
$view->vars['select_root_node'] = $form->getConfig()->getAttribute('select_root_node');
$view->vars['repository_name'] = $form->getConfig()->getAttribute('repository_name');
Expand Down
3 changes: 0 additions & 3 deletions Resources/config/doctrine_phpcr_form_types.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
<call method="setDefaults">
<argument>%sonata_admin_doctrine_phpcr.tree_block.defaults%</argument>
</call>
<call method="setTree">
<argument type="service" id="sonata.admin.doctrine_phpcr.phpcr_odm_tree" />
</call>
</service>

<service id="sonata.admin.doctrine_phpcr.form.type.phpcr_odm_tree_manager" class="Sonata\DoctrinePHPCRAdminBundle\Form\Type\TreeManagerType">
Expand Down
8 changes: 4 additions & 4 deletions Resources/config/tree.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
<services>

<service id="sonata.admin.doctrine_phpcr.tree_controller"
class="Sonata\DoctrinePHPCRAdminBundle\Controller\TreeController">
<argument type="service" id="sonata.admin.doctrine_phpcr.phpcr_odm_tree" />
class="Sonata\DoctrinePHPCRAdminBundle\Controller\TreeController">

<argument>%sonata_admin_doctrine_phpcr.tree_block.repository_name%</argument>
<argument/>
<argument>%sonata_admin_doctrine_phpcr.tree_block.defaults%</argument>
<argument>%sonata_admin_doctrine_phpcr.tree_confirm_move%</argument>
<call method="setContainer"><argument type="service" id="service_container"/></call>
</service>

<service id="sonata.admin.doctrine_phpcr.phpcr_odm_tree" class="Sonata\DoctrinePHPCRAdminBundle\Tree\PhpcrOdmTree">
<tag name="cmf.tree" alias="phpcr_odm_tree" />
<argument type="service" id="doctrine_phpcr.odm.default_document_manager" />
<argument type="service" id="sonata.admin.manager.doctrine_phpcr"/>
<argument type="service" id="sonata.admin.pool"/>
Expand All @@ -29,4 +29,4 @@

</services>

</container>
</container>
19 changes: 14 additions & 5 deletions Resources/views/Form/form_admin_fields.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,16 @@ file that was distributed with this source code.
{% include 'CmfTreeBrowserBundle:Base:tree.html.twig' %}
<script>
jQuery(function ($) {
var defaults = {% include 'SonataDoctrinePHPCRAdminBundle:Tree:routing_defaults.html.twig' with {'routing_defaults': routing_defaults} %};
{% set routing_default_values = {} %}
{% for default in routing_defaults %}
{% if 'locale' == default %}
{% set routing_default_values = routing_default_values|merge({'_locale': app.request.locale}) %}
{% elseif 'format' == default %}
{% set routing_default_values = routing_default_values|merge({'_format': app.request.format}) %}
{% else %}
{% set routing_default_values = routing_default_values|merge({default: app.request.attributes.get(default)}) %}
{% endif %}
{% endfor %}
$('#{{ id }}-tree-selector').cmfTree({
request: {
Expand All @@ -157,8 +166,7 @@ file that was distributed with this source code.
url: '{{ path('_cmf_resource', {
repositoryName: repository_name,
path: '__path__'
}) }}'.replace('__path__', nodePath)
{# todo: include routing defaults #}
}|merge(routing_default_values)) }}'.replace('__path__', nodePath)
};
},
},
Expand All @@ -179,11 +187,12 @@ file that was distributed with this source code.
{% block doctrine_phpcr_odm_tree_manager_widget %}
{{ render(controller('sonata.admin.doctrine_phpcr.tree_controller:treeAction', {
'root': form.vars.root,
'selected': false,
})) }}
{# 'selected': false,
'create_in_overlay': form.vars.create_in_overlay,
'edit_in_overlay': form.vars.edit_in_overlay,
'delete_in_overlay': form.vars.delete_in_overlay
})) }}
})) #}
{% endblock %}

{% block choice_field_mask_widget %}
Expand Down
31 changes: 24 additions & 7 deletions Resources/views/Tree/tree.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,43 @@ file that was distributed with this source code.
#}

{% set routing_default_values = {} %}
{% for default in routing_defaults %}
{% if 'locale' == default %}
{% set routing_default_values = routing_default_values|merge({'_locale': app.request.locale}) %}
{% elseif 'format' == default %}
{% set routing_default_values = routing_default_values|merge({'_format': app.request.format}) %}
{% else %}
{% set routing_default_values = routing_default_values|merge({default: app.request.attributes.get(default)}) %}
{% endif %}
{% endfor %}

{% include 'CmfTreeBrowserBundle:Base:tree.html.twig' %}
<script type="text/javascript">
jQuery(function($) {
var defaults = {% include 'SonataDoctrinePHPCRAdminBundle:Tree:routing_defaults.html.twig' with {'routing_defaults': routing_defaults} %};
$('#tree').cmfTree({
request: {
load: function (nodePath) {
return {
url: '{{ path('_cmf_resource', {
repositoryName: 'default',
repositoryName: repository_name,
root_node: root_node,
path: '__path__'
}) }}'.replace('__path__', nodePath)
{# todo: include routing defaults #}
}|merge(routing_default_values)) }}'.replace('__path__', nodePath)
};
}
},
actions: {
'edit': { url: { data: '?sonata_links.edit' }, label: 'Edit', icon: 'fa fa-pencil' },
'delete': { url: { data: '?sonata_links.delete' }, label: 'Delete', icon: 'fa fa-trash-o' }
'edit': {
url: { data: '?sonata_links.edit' },
label: "{{ 'create_item'|trans({}, 'SonataDoctrinePhpcrAdminBundle') }}",
icon: 'fa fa-pencil'
},
'delete': {
url: { data: '?sonata_links.delete' },
label: "{{ 'delete_item'|trans({}, 'SonataDoctrinePhpcrAdminBundle') }}",
icon: 'fa fa-trash-o'
}
}
});
});
Expand Down
Loading

0 comments on commit d6c232d

Please sign in to comment.