I am trying to add a block into my admin dashboard, using sonataadminbundle. I tried to follow the directives written here in the first answer : How to add custom link or button to SonataAdminBundle Dashboard in Symfony2
But I have a problem in my BlockService class.
The code is as follow :
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);
}
}
But I have a compilation error on the validatBlock, buildEdittForm and execute method :
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.
Do you have any idea ?
Thank you for reading.
I finally found the cause of my problem : I had to self-update the composer.
It looks like my composer was to old, and did not fetch every files or dependancy I needed.
So, composer self-update
saved me.