将块添加到 Sonata 管理界面

Adding a block into Sonata Admin Interface

我正在尝试使用 sonataadminbundle 在我的管理仪表板中添加一个块。我试着按照第一个答案中写的指令进行操作:How to add custom link or button to SonataAdminBundle Dashboard in Symfony2

但是我的 BlockService 有问题 class。

代码如下:

namespace AppBundle\Block;

use Symfony\Component\HttpFoundation\Response;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\CoreBundle\Validator\ErrorElement;
use Sonata\BlockBundle\Model\BlockInterface;
use Sonata\BlockBundle\Block\BaseBlockService;

class InvitationBlockService extends BaseBlockService
{
    public function getName()
    {
        return 'Invitation manager';
    }

    public function getDefaultSettings()
{
    return array();
}

public function validateBlock(ErrorElement $errorElement, BlockInterface $block)
{
}

public function buildEditForm(FormMapper $formMapper, BlockInterface $block)
{
}

public function execute(BlockInterface $block, Response $response = null)
{
    // merge settings
    $settings = array_merge($this->getDefaultSettings(), $block->getSettings());

    return $this->renderResponse('InstitutoStoricoNewsletterBundle:Block:block_invitation.html.twig', array(
        'block'     => $block,
        'settings'  => $settings
    ), $response);
}

}

但是我在 validatBlock、buildEdittForm 和 execute 方法上有一个编译错误:

Declaration must be compatible with BlockServiceInterface->validateBlock(errorElement : \Sonata\AdminBundle>\Validator\ErrorElement, block : \Sonata\BlockBundle\Model\BlockInterface) Class hierarchy checks: abstract methods implementation, implementing/overriding method is compatibility with super declaration. All violations result in PHP fatal errors. It's not recommended to disable or suppress this inspection.

你有什么想法吗?

感谢阅读。

我终于找到了问题的原因:我不得不自行更新作曲家。

看来我的作曲家太老了,没有获取我需要的所有文件或依赖项。

所以,composer self-update救了我。