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

Show description for field with custom mapping schema #338

Closed ardianys closed 12 years ago

ardianys commented 12 years ago

Another newbie question again here, sorry for bothering you all.

Finally I have made my Sonata Admin Bundle works. But I have a problem where a want to show some data with "Show" link in top menu. I can't displayed some field which have custom mapping schema.


class Milestone
{

... 
    / **
     * @ORM\ManyToOne(targetEntity="Project", inversedBy="milestones")
     * @ORM\JoinColumn(name="project_id", referencedColumnName="id")
     */
    private $project;

...
}

class Project
{
...
   /**
     * @ORM\OneToMany(targetEntity="Milestone", mappedBy="project")
     */
    private $milestones;
....
}

When I click "Show" menu for one row of my milestone data, there is no "Project" field displayed.

Then I digging inside this bundle and found some code under

public_html/symfony/vendor/bundles/Sonata/AdminBundle/Builder/ORM/ShowBuilder.php

the code is in line 49

switch($fieldDescription->getMappingType()) {
            case ClassMetadataInfo::MANY_TO_ONE:
            case ClassMetadataInfo::MANY_TO_MANY:
            case ClassMetadataInfo::ONE_TO_MANY:
            case ClassMetadataInfo::ONE_TO_ONE:
                // todo
                return;
            default:
                $list->add($fieldDescription);
        }

there is TODO comment, and when I add some code so this code become

switch($fieldDescription->getMappingType()) {
            case ClassMetadataInfo::MANY_TO_ONE:
            case ClassMetadataInfo::MANY_TO_MANY:
            case ClassMetadataInfo::ONE_TO_MANY:
            case ClassMetadataInfo::ONE_TO_ONE:
                // todo
                $list->add($fieldDescription);
                return;
            default:
                $list->add($fieldDescription);
        }

I got my project name displayed in Show page. Is it correct for adding this code to core of this bundle ?

I really new in this S2 world and need some advices,

Regards.

rande commented 12 years ago

No it is not correct, relations are not yet implement in the show view

ardianys commented 12 years ago

Thanks for your info, What should I do to meet the requirement to show mapped data in show view ? Could I do this in child bundle ?

Regards.

rande commented 12 years ago

You can contribute to the project by creating the dedicated templates to display relation ;)

ardianys commented 12 years ago

ok. thanks. I'll try to do that.