简体   繁体   中英

How to add custom button/link/anchor to sonata admin menu

First to say I'm new in sonata. searched in docs, found similar problem here but not exactly the same. I added Custom Admin not tied to any entity and added custom action:

namespace Opcja\AdminBundle\Admin;


class PriceProductAdmin extends AbstractAdmin
{
protected $baseRouteName = 'product_price';
protected $baseRoutePattern = 'product_price';


protected function configureRoutes(RouteCollection $collection)
{
    $collection->add('management');
}

}

namespace Opcja\AdminBundle\Controller;

class PriceProductAdminController extends CRUDController
{
   public function managementAction()
   {
  //    return parent::listAction(); // TODO: Change the autogenerated stub
    return new Response("aa");
   }
}

Registered like in docs:

        admin.price_product_admin:
        class: AdminBundle\Admin\PriceProductAdmin
        arguments: [~, ~, OpcjaAdminBundle:PriceProductAdmin]
        tags:
            - { name: sonata.admin, manager_type: orm, group: Products Price Management, label: Product Price }

Till here everything is ok, admin works, when i use '/management' route I see response from controller. But in BlockMenu (left side "slide down") i can se group that I gave (Products....), I see Product Price when i click this group but the link goes to "/list" (I assume its default), I want this link to point to my custom action "/management" as I defined.

I checked these: 1. https://sonata-project.org/bundles/admin/master/doc/cookbook/recipe_custom_action.html 2. https://sonata-project.org/bundles/block/master/doc/reference/your_first_block.html and Im confused - I just want link in block menu to point into my custom action(management) instead of "list". Am I supposed to add new block? create new directory and button (link 1, point 8.1.4 - tried this , it doesnt work for me)?

Try to add second parameter to configureRoutes method. Maybe it helps.

$collection->add('management', '/management');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM