3

I'm trying to add a custom block to the dashboard of SonataAdminBundle. I followed the instructinos here (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) that contains the template of the block I want to add to SonataAdmin's dashboard :

{% 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 because I tried to put the upper lines directly in config.yml and got the same result.

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...

Community
  • 1
  • 1
Etienne Noël
  • 5,988
  • 6
  • 48
  • 75
  • It seems to be everything fine. But when I included a custom service, I don't use `camellized` writting, I'd use `sonata.block.service.process_management`. Maybe it is not the solution, but you can try to change it's name, just in case. – Dani Sancas Jan 27 '14 at 20:13
  • @DaniSancas changing it did not solve my problem... – Etienne Noël Jan 27 '14 at 20:16
  • Then I see nothing. I checked my own code and everything looks similar. Maybe a stupid question but, did you remove (all) the cache files? – Dani Sancas Jan 27 '14 at 20:20
  • Actually, I think you were right, it was because I was using camellized writing and Symfony seems to automatically lower case everything... I had forgotten to change one processManagement ! thank you very much, write it as a response if you wan't and I'll accept it. – Etienne Noël Jan 27 '14 at 20:45

1 Answers1

3

The problem is how you did the letter casing in the config.yml. Always use lowercase for defining service names if you don't then Symfony converts it to lowercase.

Take a look at the coding standards for Symfony.

Service Naming Conventions:

  • A service name contains groups, separated by dots

  • The DI alias of the bundle is the first group (e.g. fos_user)

  • A service name contains groups, separated by dots

  • Use lowercase letters for service and parameter names

Community
  • 1
  • 1
Geert Wille
  • 1,656
  • 13
  • 18