new sonata block:类Symfony \ Bundle \ TwigBundle \ TwigEngine的对象无法转换为字符串

时间:2017-11-16 09:32:43

标签: sonata

我正在使用symfony 3.3和sonata block bundle 3.2。 我创建了一个新的块服务

    namespace AppBundle\Block\Service;

    use Sonata\AdminBundle\Form\FormMapper;
    use Sonata\BlockBundle\Block\BlockContextInterface;
    use Sonata\BlockBundle\Model\BlockInterface;
    use Symfony\Component\HttpFoundation\Response;
    use Symfony\Component\OptionsResolver\OptionsResolver;
    use Sonata\BlockBundle\Block\Service\AbstractAdminBlockService;
    use Sonata\CoreBundle\Model\Metadata;

    class WysiwygBlockService extends AbstractAdminBlockService
    {
    /**
     * {@inheritdoc}
     */
    public function execute(BlockContextInterface $blockContext, Response $response = null)
    {
        return $this->renderResponse($blockContext->getTemplate(), [
            'block' => $blockContext->getBlock(),
            'settings' => $blockContext->getSettings(),
        ], $response);
    }

    /**
     * {@inheritdoc}
     */
    public function buildEditForm(FormMapper $formMapper, BlockInterface $block)
    {
        $formMapper->add('settings', 'sonata_type_immutable_array', [
            'keys' => [
                ['content', 'ckeditor', []],
            ],
        ]);
    }

    /**
     * {@inheritdoc}
     */
    public function configureSettings(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'content' => 'Insert your 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', [
            'class' => 'fa fa-file-text-o',
        ]);
    }

}

当我进入后台的作曲家页面时,我收到了这个错误:

在渲染模板期间抛出异常(“Catchable Fatal Error:类Symfony \ Bundle \ TwigBundle \ TwigEngine的对象无法转换为字符串”)。

有什么想法吗?

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

我在服务声明中错过了一个参数:

# Sonata block services
app.block.service.wysiwyg:
    class: AppBundle\Block\Service\WysiwygBlockService
    arguments:
        **- "Wysiwyg"**
        - "@templating"
    tags:
        - { name: sonata.block }
    public: true