sonata-project / SonataAdminBundle

The missing Symfony Admin Generator
https://docs.sonata-project.org/projects/SonataAdminBundle
MIT License
2.11k stars 1.26k forks source link

The show action got blank and no field are shown #3008

Closed cithukyaw closed 9 years ago

cithukyaw commented 9 years ago

I'm integrating Sonata Admin Bundle into my Symfony 2.6 application by following Symfony 2 jobeet tutorial. Everything is fine except the Show action. I have an entiry "Job" and so I have src/Ibw/JobeetBundle/Admin/JobAdmin.php which have a function configurShowField(ShowMapper $showMapper) like below

<?php
namespace Ibw\JobeetBundle\Admin;

use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Validator\ErrorElement;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Show\ShowMapper;

use Ibw\JobeetBundle\Entity\Job;

class JobAdmin extends Admin
{
    // ....

    protected function configureShowField(ShowMapper $showMapper)
    {
        $showMapper
            ->add('category')
            ->add('type')
            ->add('company')
            ->add('webPath', 'string', array('template' => 'IbwJobeetBundle:JobAdmin:list_image.html.twig'))
            ->add('url')
            ->add('position')
            ->add('location')
            ->add('description')
            ->add('how_to_apply')
            ->add('is_public')
            ->add('is_activated')
            ->add('token')
            ->add('email')
            ->add('expires_at')
        ;
    }

    // ....
}

When I click the Show button and go to the view page (admin/ibw/jobeet/job/xxx/show), it shows none of the fields. The original template processed is /vendor/sonata-project/admin-bundle/Resources/views/CRUD/base_show.html.twig:

{% extends base_template %}

{% block actions %}
    <li>{% include 'SonataAdminBundle:Button:edit_button.html.twig' %}</li>
    <li>{% include 'SonataAdminBundle:Button:history_button.html.twig' %}</li>
    <li>{% include 'SonataAdminBundle:Button:list_button.html.twig' %}</li>
    <li>{% include 'SonataAdminBundle:Button:create_button.html.twig' %}</li>
{% endblock %}

{% block tab_menu %}{{ knp_menu_render(admin.sidemenu(action), {'currentClass' : 'active', 'template': admin_pool.getTemplate('tab_menu_template')}, 'twig') }}{% endblock %}

{% block show %}
    <div class="sonata-ba-view">
        ***
        {{ sonata_block_render_event('sonata.admin.show.top', { 'admin': admin, 'object': object }) }}

        {% for name, view_group in admin.showgroups %}
            <table class="table table-bordered">
                {% if name %}
                    <thead>
                        {% block show_title %}
                            <tr class="sonata-ba-view-title">
                                <th colspan="2">
                                    {{ admin.trans(name) }}
                                </th>
                            </tr>
                        {% endblock %}
                    </thead>
                {% endif %}

                <tbody>
                    {% for field_name in view_group.fields %}
                        {% block show_field %}
                            <tr class="sonata-ba-view-container">
                                {% if elements[field_name] is defined %}
                                    {{ elements[field_name]|render_view_element(object) }}
                                {% endif %}
                            </tr>
                        {% endblock %}
                    {% endfor %}
                </tbody>
            </table>
        {% endfor %}

        {{ sonata_block_render_event('sonata.admin.show.bottom', { 'admin': admin, 'object': object }) }}

    </div>
{% endblock %}

The inner content of <div class="sonata-ba-view"></div> is not shown except three asterisks I printed. Is there any configuration I'm missing?

cithukyaw commented 9 years ago

I traced in configureShowField(), but it seems not calling the method.

thibaut-algrin commented 9 years ago

Hello,

It's not configureShowField() but configureShowFields(): you are missing the 'S'.

cithukyaw commented 9 years ago

Oh, that's correct. Thank you. The jobeet tutorial is wrong.

hieuit7 commented 9 years ago

i want to override block show in base_show.html.twig but, i can't. my config is the same above!!

cithukyaw commented 9 years ago

@hieuit7 I think you could create \app\Resources\SonataAdminBundle\views\CRUD\base_show.html.twig.

hieuit7 commented 9 years ago

@cithukyaw i sorry, i sloved my problem! incorrect in my code!! setTemplate instead of setTemplates for array templates!!!