SonataAdmin - The custom block I'm trying to build is not found

906 views
Skip to first unread message

Etienne Noël

unread,
Jan 27, 2014, 2:13:03 PM1/27/14
to sonat...@googlegroups.com
I'm trying to add a custom block to the dashboard of SonataAdminBundle. I followed the instructinos here (http://stackoverflow.com/questions/14113259/how-to-add-custom-link-or-button-to-sonataadminbundle-dashboard-in-symfony2) and I'm getting the following error : 

     RuntimeException: The block service `sonata.block.service.processManagement` does not exist 

Here's what I did. I have a file named "ProcessManagementBlockService.php" which contains the following:

    <?php
    
    namespace IMA\ProcessManagementBundle\Block;
    
    use Symfony\Component\HttpFoundation\Response;
    
    use Sonata\AdminBundle\Form\FormMapper;
    use Sonata\AdminBundle\Validator\ErrorElement;
    
    use Sonata\BlockBundle\Model\BlockInterface;
    
    use Sonata\BlockBundle\Block\BlockContextInterface;
    use Sonata\BlockBundle\Block\BaseBlockService;
    
    class ProcessManagementBlockService extends BaseBlockService
    {
        public function getName()
        {
            return 'My Newsletter';
        }
    
        public function getDefaultSettings()
        {
            return array();
        }
    
        public function validateBlock(ErrorElement $errorElement, BlockInterface $block)
        {
        }
    
        public function buildEditForm(FormMapper $formMapper, BlockInterface $block)
        {
        }
    
        public function execute(BlockContextInterface $block, Response $response = null)
        {
            // merge settings
            $settings = array_merge($this->getDefaultSettings(), $block->getSettings());
    
            return $this->renderResponse('IMAProcessManagement:Block:blockProcessManagement.html.twig', array(
                'block'     => $block,
                'settings'  => $settings
            ), $response);
        }
    }

I also created a file (views/Block/blockProcessManagement.html.twig) in which I have :

    {% extends 'SonataBlockBundle:Block:block_base.html.twig' %}
    
    {% block block %}
        <table class="table table-bordered table-striped sonata-ba-list">
            <thead>
            <tr>
                <th colspan="3">Newsletter - inviare</th>
            </tr>
            </thead>
    
            <tbody>
            <tr>
                <td>
                    <div class="btn-group" align="center">
                        <a class="btn btn-small" href="#">Servizio Newsletter</a>
                    </div>
                </td>
            </tr>
            </tbody>
        </table>
    {% endblock %}

Also, I in the services.yml file of my bundle, I have the following 

    services:
    #    ima_process_management.example:
    #        class: %ima_process_management.example.class%
    #        arguments: [@service_id, "plain_value", %parameter%]
        sonata.block.service.processManagement:
            class: IMA\ProcessManagementBundle\Block\ProcessManagementBlockService
            arguments: [ "sonata.block.service.processManagement", @templating ]
            tags:
                - { name: sonata.block }

I know this file is properly loaded.

Finally, I added in the main config.yml file of my project

    sonata_block:
        default_contexts: [cms]
        blocks:
            # Enable the SonataAdminBundle block
            sonata.admin.block.admin_list:
                contexts:   [admin]
            # Your other blocks
            sonata.block.service.text:
            sonata.block.service.rss:
            sonata.admin.block.search_result:
            sonata.block.service.processManagement: ~

and 

    sonata_admin:
        templates:
            dashboard: SonataAdminBundle:Core:dashboard.html.twig
        dashboard:
            blocks:
                - { position: left, type: sonata.admin.block.admin_list }
                - { position: left, type: sonata.block.service.processManagement}

I really don't know why I'm getting the error that the service does not exist...

Thomas Rabaix

unread,
Jan 27, 2014, 2:15:23 PM1/27/14
to sonat...@googlegroups.com

Can you check that the service exists in the generated container file ?

--
Thomas Rabaix
http://rabaix.net - http://sonata-project.org

--
You received this message because you are subscribed to the Google Groups "sonata-devs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonata-devs...@googlegroups.com.
To post to this group, send email to sonat...@googlegroups.com.
Visit this group at http://groups.google.com/group/sonata-devs.
For more options, visit https://groups.google.com/groups/opt_out.

Etienne Noël

unread,
Jan 27, 2014, 2:18:10 PM1/27/14
to sonat...@googlegroups.com, tho...@rabaix.net
I have the following in appDevDebugProjectContainer

parameter key="sonata.block.service.processManagement" type="collection">
        <parameter key="contexts" type="collection"/>
        <parameter key="cache">sonata.cache.noop</parameter>
        <parameter key="settings" type="collection"/>
      </parameter>
    </parameter>
    <parameter key="sonata_block.blocks_by_class" type="collection"/>
    <parameter key="sonata_block.cache_blocks" type="collection">
      <parameter key="by_type" type="collection">
        <parameter key="sonata.admin.block.admin_list">sonata.cache.noop</parameter>
        <parameter key="sonata.block.service.text">sonata.cache.noop</parameter>
        <parameter key="sonata.block.service.rss">sonata.cache.noop</parameter>
        <parameter key="sonata.admin.block.search_result">sonata.cache.noop</parameter>
        <parameter key="sonata.block.service.processManagement">sonata.cache.noop</parameter>
      </parameter>

so from this I guess it exists

Thomas Rabaix

unread,
Jan 27, 2014, 2:20:46 PM1/27/14
to sonat...@googlegroups.com

So the service is not registerd into the container.  Check how you load the yaml containing the service declaration.

Etienne Noël

unread,
Jan 27, 2014, 2:29:38 PM1/27/14
to sonat...@googlegroups.com
I'm loading services.yml in the IMAProcessManagementExtension (in DependencyInjection)

        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('services.yml');
        $loader->load('admin.yml');


2014-01-27 Thomas Rabaix <tho...@rabaix.net>

--
You received this message because you are subscribed to a topic in the Google Groups "sonata-devs" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonata-devs/CulMNbIYfYY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonata-devs...@googlegroups.com.

Etienne Noël

unread,
Jan 27, 2014, 3:47:11 PM1/27/14
to sonat...@googlegroups.com
Okay, I found it, never use camellized words for that....


2014-01-27 Thomas Rabaix <tho...@rabaix.net>
To unsubscribe from this group and stop receiving emails from it, send an email to sonata-devs+unsubscribe@googlegroups.com.

To post to this group, send email to sonat...@googlegroups.com.
Visit this group at http://groups.google.com/group/sonata-devs.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to a topic in the Google Groups "sonata-devs" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonata-devs/CulMNbIYfYY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonata-devs+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages