symfony - exception during the rendering of a template: "The block service `app.service.block.custom` does not exist" -
i'm trying build custom block sonata, moment i'm trying simple block display text, cannot render template seems service can't found.
i have block declared in config.yml
sonata_block: default_contexts: [cms] blocks: app.service.block.portfolio: dashboard: blocks: - { position: right, type: app.service.block.portfolio, settings: { content: "<h2>this test block</h2>"} }
i can see service up:
app/console debug:container | grep app.service.block.portfolio app.service.block.portfolio app\corebundle\block\blockportfolio
this code used:
<?php namespace app\corebundle\block; use sonata\blockbundle\block\service\abstractadminblockservice; use sonata\adminbundle\form\formmapper; use sonata\blockbundle\block\blockcontextinterface; use sonata\blockbundle\model\blockinterface; use sonata\corebundle\model\metadata; use symfony\component\httpfoundation\response; use symfony\component\optionsresolver\optionsresolver; use jms\diextrabundle\annotation di; /** * @di\service("app.service.block.portfolio") */ class blockportfolio extends abstractadminblockservice { /** * {@inheritdoc} */ public function execute(blockcontextinterface $blockcontext, response $response = null) { return $this->renderresponse($blockcontext->gettemplate(), array( 'block' => $blockcontext->getblock(), 'settings' => $blockcontext->getsettings(), ), $response); } /** * {@inheritdoc} */ public function buildeditform(formmapper $formmapper, blockinterface $block) { $formmapper->add('settings', 'sonata_type_immutable_array', array( 'keys' => array( array('content', 'textarea', array()), ), )); } /** * {@inheritdoc} */ public function configuresettings(optionsresolver $resolver) { $resolver->setdefaults(array( 'content' => 'insert custom content here', 'template' => 'sonatablockbundle:block:block_core_text.html.twig', )); } /** * {@inheritdoc} */ public function getblockmetadata($code = null) { return new metadata($this->getname(), (!is_null($code) ? $code : $this->getname()), false, 'sonatablockbundle', array( 'class' => 'fa fa-file-text-o', )); }
}
anyone has clue ?
regards, julien
ok, found answer, missing tag in service.
/** * @di\service("app.service.block.portfolio") * @di\tag(name="sonata.block") */
i'm not sure why need tag, though. if knows reason, i'd happy here it.
cheers, julien
Comments
Post a Comment