public function execute()
{
/** @var ContentBlockRepository $contentBlockRepository */
$contentBlockRepository = $this->get('content_blocks.repository.content_block');
$contentBlock = $contentBlockRepository->findOneByIdAndLocale($this->getParameter('id', 'int'), Locale::workingLocale());
if ($contentBlock === null) {
return $this->redirect(BackendModel::createURLForAction('Index', null, null, ['error' => 'non-existing']));
}
// The command bus will handle the saving of the content block in the database.
$this->get('command_bus')->handle(new DeleteContentBlock($contentBlock));
$this->get('event_dispatcher')->dispatch(ContentBlockDeleted::EVENT_NAME, new ContentBlockDeleted($contentBlock));
return $this->redirect(BackendModel::createURLForAction('Index', null, null, ['report' => 'deleted', 'var' => $contentBlock->getTitle()]));
}