netlabs/admin-extensions-bundle

Extension for SonataAdminBundle: list scopes

1.0.0 2014-04-10 05:21 UTC

README

Installation

  • composer.json
"require": {
    "netlabs/admin-extensions-bundle": "1.0.*"
}
  • app/AppKernel.php
new NetLabs\AdminExtensionsBundle\NetLabsAdminExtensionsBundle()

Configuration

  • app/config/config.yml
sonata_admin:
    # ...
    templates:
        list: "NetLabsAdminExtensionsBundle:Admin:list.html.twig"

All *Admin classes

use NetLabs\AdminExtensionsBundle\Admin\BaseAdmin as Admin;

class AdministratorAdmin extends Admin
{
    //...

All *AdminController classes

use NetLabs\AdminExtensionsBundle\Controller\BaseAdminController as Controller;

class AdministratorAdminController extends Controller
{
    //...

Usage

  • any *Admin class
protected function configureListFields(ListMapper $listMapper)
{
    $this
        ->addScopeGroup('myScopeGroup', 'My scope group name') // not required (default group is "main")
            ->addScope('all', 'All', true, false)              // scope ID, scope name, is default, is method required
            ->addScope('read', 'Read')
            ->addScope('notRead', 'Not read');

    //...
}

public function addMyScopeGroupReadScopeQuery($query)
{
    $query->where($query->getRootAlias() . '.isRead = true');
}

public function addMyScopeGroupNotReadScopeQuery($query)
{
    $query->where($query->getRootAlias() . '.isRead = false');
}