简体   繁体   中英

Show sidebar in show view - Sonata admin bundle

Hello i would like to show the sidebar in sonata admin bundle, however i can't find a good example, this is the code i use to show it in the edit mode:

protected function configureSideMenu(MenuItemInterface $menu, $action, AdminInterface $childAdmin = null) {
    if (!$childAdmin && !in_array($action, array('edit'))) {
        return;
    }

    $admin = $this->isChild() ? $this->getParent() : $this;
    $id = $admin->getRequest()->get('id');

    $menu->addChild(
        'view',
        array('uri' => $admin->generateUrl('edit', array('id' => $id)))
    );

    $menu->addChild(
        'replies',
        array('uri' => $admin->generateUrl('sonata.admin.module.application.replies.list', array('id' => $id)))
    );
}

however i would like to make it appear in the show view since i am displaying that as default because the form should not be editable.

This is my configureShowFields

protected function configureShowFields(ShowMapper $showMapper) {
    $showMapper
        ->add('application')
        ->add('denied')
        ->add('details', 'string', array('template' => 'MyBundle:Admin:jsonToTable.html.twig'))
    ;
}

Found it, just add the correct action to the configureSideMenu function

protected function configureSideMenu(MenuItemInterface $menu, $action, AdminInterface $childAdmin = null)
{
    if (!$childAdmin && !in_array($action, array('edit', 'show'))) {
        return;
    }
    $admin = $this->isChild() ? $this->getParent() : $this;
    $id = $admin->getRequest()->get('id');

    $menu->addChild(
       'view',
        array('uri' => $admin->generateUrl('show', array('id' => $id)))
    );

    $menu->addChild(
        'replies',
        array('uri' => $admin->generateUrl('sonata.admin.module.application.replies.list', array('id' => $id)))
    );
}

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