Hi,

I would like to extend the ShowMapper from AdminBundle to override "with" 
function.
I created a class ShowMapper inside a "Show" directory in my bundle and it 
looks like : 

class ShowMapper extends BaseShowMapper
{

    protected $list;

    /**
     * @param ShowBuilderInterface       $showBuilder
     * @param FieldDescriptionCollection $list
     * @param AdminInterface             $admin
     */
    public function __construct(ShowBuilderInterface $showBuilder, 
FieldDescriptionCollection $list, AdminInterface $admin)
    {
        parent::__construct($showBuilder, $admin);
        $this->list        = $list;
    }

    /**
     * Add new group or tab (if parameter "tab=true" is available in 
options)
     *
     * @param string $name
     * @param array  $options
     *
     * @return $this
     *
     * @throws \RuntimeException
     */
    public function with($name, array $options = array())
    {
       
        $defaultOptions = array(
            'collapsed'          => false,
            'class'              => false,
            'description'        => false,
            'icon'               => false,
            'translation_domain' => null,
            'name'               => $name,
            'box_class'          => 'box box-primary',
        );

        $code = $name;

        // Open
        if (array_key_exists('tab', $options) && $options['tab']) {
            $tabs = $this->getTabs();

            if ($this->currentTab) {
                if (isset($tabs[$this->currentTab]['auto_created']) && true 
=== $tabs[$this->currentTab]['auto_created']) {
                    throw new \RuntimeException('New tab was added 
automatically when you have added field or group. You should close current 
tab before adding new one OR add tabs before adding groups and fields.');
                } else {
                    throw new \RuntimeException(sprintf('You should close 
previous tab "%s" with end() before adding new tab "%s".', $this->currentTab
, $name));
                }
            } elseif ($this->currentGroup) {
                throw new \RuntimeException(sprintf('You should open tab 
before adding new group "%s".', $name));
            }

            if (!isset($tabs[$name])) {
                $tabs[$name] = array();
            }

            $tabs[$code] = array_merge($defaultOptions, array(
                'auto_created'       => false,
                'groups'             => array(),
            ), $tabs[$code], $options);

            $this->currentTab = $code;

        } else {

            if ($this->currentGroup) {
                throw new \RuntimeException(sprintf('You should close 
previous group "%s" with end() before adding new tab "%s".', $this->
currentGroup, $name));
            }

            if (!$this->currentTab) {
                // no tab define
                $this->with('default', array(
                    'tab'                => true,
                    'auto_created'       => true,
                    'translation_domain' => isset($options[
'translation_domain']) ? $options['translation_domain'] : null
                )); // add new tab automatically
            }

            // if no tab is selected, we go the the main one named '_' ..
            if ($this->currentTab !== 'default') {
                $code = $this->currentTab.'.'.$name; // groups with the 
same name can be on different tabs, so we prefix them in order to make 
unique group name
            }

            $groups = $this->getGroups();
            if (!isset($groups[$code])) {
                $groups[$code] = array();
            }

            $groups[$code] = array_merge($defaultOptions, array(
                'fields' => array(),
            ), $groups[$code], $options);

            $this->currentGroup = $code;
            $this->setGroups($groups);
            $tabs = $this->getTabs();
        }

        if ($this->currentGroup && isset($tabs[$this->currentTab]) && !
in_array($this->currentGroup, $tabs[$this->currentTab]['groups'])) {
            $tabs[$this->currentTab]['groups'][] = $this->currentGroup;
        }

        $this->setTabs($tabs);

        return $this;
    }
}

So in my Admin class, I replace the use statement of AdminBundle with mine 
but I want to go to the show action of my entity, I just got something like 
: 

must be an instance of XXXX\Show\ShowMapper, instance of Sonata\AdminBundle\
Show\ShowMapper given

where should I configure the service to set the good ShowMapper ?

Thanks


-- 
You received this message because you are subscribed to the Google Groups 
"sonata-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sonata-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to