Hi all, i'm following directions from
http://sonata-project.org/bundles/block/2-0/doc/reference/your_first_block.html
to create a new block.
I've defined a TwigBlockService class that extends BaseBlockService in
my bundle as follows:
namespace OB\TwigBlockBundle\Block\Service;
use Symfony\Component\HttpFoundation\Response;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Validator\ErrorElement;
use Sonata\BlockBundle\Model\BlockInterface;
use Sonata\BlockBundle\Block\BaseBlockService;
class TwigBlockService extends BaseBlockService {
/**
* {@inheritdoc}
*/
public function execute(BlockInterface $block, Response $response =
null) {
$settings = array_merge($this->getDefaultSettings(),
$block->getSettings());
return
$this->renderResponse('OBTwigBlockBundle:Twig:block_twig.html.twig', array(
'block' => $block,
'settings' => $settings
), $response);
}
public function validateBlock(ErrorElement $errorElement,
BlockInterface $block) {
}
/**
* {@inheritdoc}
*/
public function buildEditForm(FormMapper $formMapper, BlockInterface
$block) {
$formMapper->add('settings', 'sonata_type_immutable_array', array(
'keys' => array(
array('content', 'text', array()),
)
));
}
/**
* {@inheritdoc}
*/
public function getName() {
return 'Twig';
}
/**
* {@inheritdoc}
*/
function getDefaultSettings() {
return array(
'template' => 'Insert your custom content here',
);
}
}
and i've defined a service like this in the services.xml of my bundle:
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="
http://symfony.com/schema/dic/services"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://symfony.com/schema/dic/services
http://symfony.com/schema/dic/services/services-1.0.xsd">
<!-- <service id="ob.block.service.twig"
class="Sonata\BlockBundle\Block\Service\RssBlockService" public="false">-->
<services>
<service id="ob.block.service.twig"
class="OB\TwigBlockBundle\Block\Service\TwigBlockService" public="false">
<tag name="sonata.block" />
<argument>ob.block.service.twig</argument>
<argument type="service" id="templating" />
</service>
</services>
</container>
I've also added the following line in my app config.yml:
sonata_block:
default_contexts: [cms]
blocks:
sonata.admin.block.admin_list:
contexts: [admin]
sonata.block.service.text:
sonata.block.service.rss:
# ADDED
ob.block.service.twig:
I'm getting problems with the service that is not created, as i can see
from the output of:
app/console container:debug
and the service isn't listed
Also
app/console sonata:block:debug
states that the service does not exist, and gives the following error:
You have requested a non-existent service "ob.block.service.twig".
The problem seems to be like this one:
https://github.com/sonata-project/SonataBlockBundle/issues/8
What's wrong with the service definition ?
Any ideas about why the service isn't created ?
Any help is apreciaded,
Bye