简体   繁体   中英

Missing action 'edit' in SonataAdminBundle

Why SonataAdminBundle action list no action 'edit'. There is only a 'Delete'. In the tutorial, I saw that this action should prisutstyvat default. How to add this action in Admin page? My UserAdmin.php:

<?php
// src/Acme/DemoBundle/Admin/PostAdmin.php

namespace Acme\AdminBundle\Admin;
use Sonata\AdminBundle\Route\RouteCollection;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;

class UserAdmin extends Admin
{
    protected $baseRoutePattern = 'users';


    // Fields to be shown on create/edit forms
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->add('first_name', 'text')
            ->add('last_name', 'text')
            ->add('username', 'text')
            ->add('email', 'text')
            ->add('plainPassword', 'password')
            ->add('roles','choice',array('choices'=>$this->getConfigurationPool()->getContainer()->getParameter('security.role_hierarchy.roles'),'multiple'=>true ));

        ;
    }

    // Fields to be shown on filter forms
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
    {
        $datagridMapper
            ->add('id')
            ->add('first_name')
            ->add('last_name')
            ->add('username')
            ->add('email')

        ;
    }
    // Fields to be shown on lists
    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->add('id')
            ->add('first_name')
            ->add('last_name')
            ->add('username')
            ->add('email')
            ->add('roles')
        ;
    }


}

you can easily add or remove action by calling add method in $formMapper of configureFormFields

 /**
 * @param ListMapper $listMapper
 */
protected function configureListFields(ListMapper $listMapper)
{
    $listMapper
        ->add('_action', 'actions', array(
            'actions' => array(
                'edit' => array(),
                'delete' => array(),
            )
        ))
    ;
}

You also can use addIdentifier() instead of add() if you don't like the action buttons.

// addIdentifier allows to specify that this column will provide a link to the entity's edition
$listMapper->addIdentifier('name');

http://sonata-project.org/bundles/admin/master/doc/reference/action_list.html

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