<?php
namespace App\Blocks;
use Doctrine\ORM\EntityManagerInterface;
class Block
{
public function __construct(\App\Entity\Content\Block $block, EntityManagerInterface $entityManager, \Twig\Environment $twig)
{
$this->block = $block;
$this->em = $entityManager;
$this->twig = $twig;
}
public function getRequiresForm()
{
return false;
}
public function cleanData($data)
{
return $data;
}
public function getDirectory()
{
throw new \Exception("Block directory not defined!");
}
public function applyDataDefaults($data)
{
return $data;
}
public function renderAdminPreviewContent()
{
return $this->twig->render('Blocks/' . $this->getDirectory() . '/Admin/renderAdminPreviewContent.html.twig', array(
'block' => array(
'identifier' => $this->block->getId(),
'block' => $this->block,
'instance' => $this
),
'data' => $this->applyDataDefaults($this->block->getData())
));
}
public function renderAdminBlockDataFields()
{
return $this->twig->render('Blocks/' . $this->getDirectory() . '/Admin/renderAdminBlockDataFields.html.twig', array(
'block' => array(
'identifier' => $this->block->getId(),
'block' => $this->block,
'instance' => $this
),
'data' => $this->applyDataDefaults($this->block->getData())
));
}
public function renderAdminEditBlockModal()
{
return $this->twig->render('Blocks/' . $this->getDirectory() . '/Admin/renderAdminEditBlockModal.html.twig', array(
'block' => array(
'identifier' => $this->block->getId(),
'block' => $this->block,
'instance' => $this
),
'data' => $this->applyDataDefaults($this->block->getData())
));
}
public function renderAdminJavascript()
{
return $this->twig->render('Blocks/' . $this->getDirectory() . '/Admin/renderAdminJavascript.html.twig', array(
'block' => array(
'identifier' => $this->block->getId(),
'block' => $this->block,
'instance' => $this
),
'data' => $this->applyDataDefaults($this->block->getData())
));
}
public function renderFrontend()
{
return $this->twig->render('Blocks/' . $this->getDirectory() . '/Frontend/renderFrontend.html.twig', array(
'block' => array(
'identifier' => $this->block->getId(),
'block' => $this->block,
'instance' => $this
),
'data' => $this->applyDataDefaults($this->block->getData())
));
}
}