Skip to content

Commit

Permalink
Refactor AdminExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Rabaix committed Mar 7, 2012
1 parent 19a7b76 commit 309d399
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 17 deletions.
8 changes: 7 additions & 1 deletion Admin/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,13 @@ public function getList()
*/
public function createQuery($context = 'list')
{
return $this->getModelManager()->createQuery($this->class);
$query = $this->getModelManager()->createQuery($this->class);

foreach ($this->extensions as $extension) {
$extension->configureQuery($this, $query, $context);
}

return $query;
}

/**
Expand Down
73 changes: 73 additions & 0 deletions Admin/AdminExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
/*
* This file is part of the Sonata package.
*
* (c) Thomas Rabaix <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\AdminBundle\Admin;

use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Show\ShowMapper;
use Sonata\AdminBundle\Route\RouteCollection;
use Sonata\AdminBundle\Validator\ErrorElement;
use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;

use Knp\Menu\ItemInterface as MenuItemInterface;

abstract class AdminExtension implements AdminExtensionInterface
{
/**
* {@inheritdoc}
*/
public function configureFormFields(FormMapper $form)
{}

/**
* {@inheritdoc}
*/
public function configureListFields(ListMapper $list)
{}

/**
* {@inheritdoc}
*/
public function configureDatagridFilters(DatagridMapper $filter)
{}

/**
* {@inheritdoc}
*/
public function configureShowFields(ShowMapper $filter)
{}

/**
* {@inheritdoc}
*/
public function configureRoutes(AdminInterface $admin, RouteCollection $collection)
{}

/**
* {@inheritdoc}
*/
public function configureSideMenu(AdminInterface $admin, MenuItemInterface $menu, $action, AdminInterface $childAdmin = null)
{}

/**
* {@inheritdoc}
*/
public function validate(AdminInterface $admin, ErrorElement $errorElement, $object)
{}

/**
* {@inheritdoc}
*/
public function configureQuery(AdminInterface $admin, ProxyQueryInterface $query, $context = 'list')
{}
}
33 changes: 17 additions & 16 deletions Admin/AdminExtensionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,63 +17,64 @@
use Sonata\AdminBundle\Route\RouteCollection;
use Sonata\AdminBundle\Validator\ErrorElement;
use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;

use Knp\Menu\ItemInterface as MenuItemInterface;

interface AdminExtensionInterface
{
/**
* @abstract
* @param \Sonata\AdminBundle\Form\FormMapper $form
* @return void
*/
function configureFormFields(FormMapper $form);

/**
* @abstract
* @param \Sonata\AdminBundle\Datagrid\ListMapper $list
* @return void
*/
function configureListFields(ListMapper $list);

/**
* @abstract
* @param \Sonata\AdminBundle\Datagrid\DatagridMapper $filter
* @return void
*/
function configureDatagridFilters(DatagridMapper $filter);

/**
* @abstract
* @param \Sonata\AdminBundle\Show\ShowMapper $filter
* @return void
*/
function configureShowFields(ShowMapper $filter);

/**
* @abstract
* @param Admin $admin
* @param AdminInterface $admin
* @param \Sonata\AdminBundle\Route\RouteCollection $collection
* @return void
*/
function configureRoutes(Admin $admin, RouteCollection $collection);
function configureRoutes(AdminInterface $admin, RouteCollection $collection);

/**
* @abstract
* @param Admin $admin
* @param \Knp\Menu\MenuItem $menu
* @param string $action
* @param null|Admin $childAdmin
* @param AdminInterface $admin
* @param \Knp\Menu\ItemInterface $menu
* @param $action
* @param null|AdminInterface $childAdmin
* @return void
*/
function configureSideMenu(Admin $admin, MenuItemInterface $menu, $action, Admin $childAdmin = null);
function configureSideMenu(AdminInterface $admin, MenuItemInterface $menu, $action, AdminInterface $childAdmin = null);

/**
* @abstract
* @param Admin $admin
* @param AdminInterface $admin
* @param \Sonata\AdminBundle\Validator\ErrorElement $errorElement
* @param $object
* @return void
*/
function validate(Admin $admin, ErrorElement $errorElement, $object);
function validate(AdminInterface $admin, ErrorElement $errorElement, $object);

/**
* @param \Sonata\AdminBundle\Datagrid\ProxyQueryInterface $query
* @param string $context
* @return void
*/
function configureQuery(AdminInterface $admin, ProxyQueryInterface $query, $context = 'list');
}
5 changes: 5 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
07/03/2012
----------

* Extension : refactor the AdminExtensionInterface to use the proper AdminInterface, add a new configureQuery method

04/09/2011
----------
* Add a delete option on widget with edit = list
Expand Down

0 comments on commit 309d399

Please sign in to comment.