Permalink
Browse files

Added block configuration

  • Loading branch information...
rvanlaarhoven committed Jan 29, 2016
1 parent aa25ccb commit f124e2e556913f5ee593b4f28254259f32d17c20
@@ -3,6 +3,7 @@
namespace Opifer\ContentBundle\Block\Service;
use Opifer\ContentBundle\Entity\Block;
use Opifer\ContentBundle\Environment\Environment;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Opifer\ContentBundle\Model\BlockInterface;
use Symfony\Component\Form\FormInterface;
@@ -19,9 +20,6 @@
*/
abstract class AbstractBlockService
{
/** @var string */
protected $view;
/** @var string */
protected $manageView = 'OpiferContentBundle:Block:manage.html.twig';
@@ -31,14 +29,22 @@
/** @var EngineInterface */
protected $templating;
/**
* The block configuration
*
* @var array
*/
protected $config;
const FORM_GROUP_PROPERTIES = 'properties';
/**
* @param EngineInterface $templating
*/
public function __construct(EngineInterface $templating)
public function __construct(EngineInterface $templating, array $config)
{
$this->templating = $templating;
$this->config = $config;
}
/**
@@ -48,10 +54,10 @@ public function execute(BlockInterface $block, Response $response = null)
{
$this->load($block);
$parameters = array(
'block_service' => $this,
'block' => $block,
);
$parameters = [
'block_service' => $this,
'block' => $block,
];
return $this->renderResponse($this->getView($block), $parameters, $response);
}
@@ -63,12 +69,12 @@ public function manage(BlockInterface $block, Response $response = null)
{
$this->load($block);
$parameters = array(
$parameters = [
'block_service' => $this,
'block' => $block,
'block_view' => $this->getView($block),
'manage_type' => $this->getManageFormTypeName(),
);
];
return $this->renderResponse($this->getManageView($block), $parameters, $response);
}
@@ -98,7 +104,10 @@ public function setEnvironment($environment)
*/
public function getName(BlockInterface $block = null)
{
return $this->name;
$class = str_replace(__NAMESPACE__ . '\\', '', get_class($this));
$shortName = str_replace('BlockService', '', $class);
return $shortName;
}
/**
@@ -133,7 +142,7 @@ public function setView($view)
*/
public function getView(BlockInterface $block)
{
return $this->view;
return $this->config['view'];
}
/**
@@ -9,25 +9,10 @@
use Symfony\Component\Form\FormBuilderInterface;
/**
* Class ButtonBlockService
*
* @package Opifer\ContentBundle\Block
* Button Block Service
*/
class ButtonBlockService extends AbstractBlockService implements BlockServiceInterface, ToolsetMemberInterface
{
protected $view = 'OpiferContentBundle:Block:Content/button.html.twig';
/** @var array */
protected $styles;
/**
* {@inheritDoc}
*/
public function getName(BlockInterface $block = null)
{
return 'Button';
}
/**
* {@inheritdoc}
*/
@@ -50,10 +35,10 @@ public function buildManageForm(FormBuilderInterface $builder, array $options)
->add('extra_classes', 'text', ['attr' => ['help_text' => 'help.extra_classes']]);
if ($this->styles) {
if ($this->config['styles']) {
$propertiesForm->add('styles', 'choice', [
'label' => 'label.styling',
'choices' => array_combine($this->styles, $this->styles),
'choices' => array_combine($this->config['styles'], $this->config['styles']),
'required' => false,
'expanded' => true,
'multiple' => true,
@@ -81,15 +66,7 @@ public function createBlock()
*/
public function getStyles()
{
return $this->styles;
}
/**
* @param array $styles
*/
public function setStyles($styles)
{
$this->styles = $styles;
return $this->config['styles'];
}
/**
@@ -17,26 +17,6 @@
*/
class CarouselBlockService extends AbstractBlockService implements BlockServiceInterface, ToolsetMemberInterface
{
protected $view = 'OpiferContentBundle:Block:Content/carousel.html.twig';
/**
* Constructor.
*
* @param EngineInterface $templating
*/
public function __construct(EngineInterface $templating)
{
parent::__construct($templating);
}
/**
* {@inheritDoc}
*/
public function getName(BlockInterface $block = null)
{
return 'Carousel';
}
/**
* {@inheritDoc}
*/
@@ -14,19 +14,6 @@
*/
class CarouselSlideBlockService extends AbstractBlockService implements BlockServiceInterface, ToolsetMemberInterface
{
protected $view = 'OpiferContentBundle:Block:Content/carousel_slide.html.twig';
/** @var array */
protected $styles;
/**
* {@inheritDoc}
*/
public function getName(BlockInterface $block = null)
{
return 'Carousel slide';
}
/**
* {@inheritdoc}
*/
@@ -39,12 +26,12 @@ public function buildManageForm(FormBuilderInterface $builder, array $options)
->add('extra_classes', 'text', ['attr' => ['help_text' => 'help.extra_classes']]);
if ($this->styles) {
if ($this->config['styles']) {
$propertiesForm
->add('styles', 'choice', [
'label' => 'label.styling',
'choices' => array_combine($this->styles, $this->styles),
'choices' => array_combine($this->config['styles'], $this->config['styles']),
'required' => false,
'expanded' => true,
'multiple' => true,
@@ -77,15 +64,15 @@ public function createBlock()
*/
public function getStyles()
{
return $this->styles;
return $this->config['styles'];
}
/**
* @param array $styles
*/
public function setStyles($styles)
{
$this->styles = $styles;
$this->config['styles'] = $styles;
}
/**
@@ -26,27 +26,19 @@ class CollectionBlockService extends AbstractBlockService implements BlockServic
{
/** @var ContentManagerInterface */
protected $contentManager;
protected $view = 'OpiferContentBundle:Block:Content/collection.html.twig';
/**
* @param EngineInterface $templating
* @param ContentManagerInterface $contentManager
* @param array $config
*/
public function __construct(EngineInterface $templating, ContentManagerInterface $contentManager)
public function __construct(EngineInterface $templating, ContentManagerInterface $contentManager, array $config)
{
parent::__construct($templating);
parent::__construct($templating, $config);
$this->contentManager = $contentManager;
}
/**
* {@inheritDoc}
*/
public function getName(BlockInterface $block = null)
{
return 'Collection';
}
/**
* {@inheritdoc}
*/
@@ -22,15 +22,11 @@ class ColumnBlockService extends AbstractBlockService implements BlockServiceInt
/** @var integer */
protected $columnCount = 1;
/** @var string */
protected $view = 'OpiferContentBundle:Block:Layout/layout.html.twig';
/**
* {@inheritdoc}
*/
public function execute(BlockInterface $block, Response $response = null)
{
$parameters = array(
'block_service' => $this,
'block' => $block,
@@ -63,7 +59,6 @@ public function buildManageForm(FormBuilderInterface $builder, array $options)
{
parent::buildManageForm($builder, $options);
$propertiesForm = $builder->create('properties', 'form')
->add('id', 'text', ['attr' => ['help_text' => 'help.html_id']])
->add('extra_classes', 'text', ['attr' => ['help_text' => 'help.extra_classes']]);
@@ -110,7 +105,6 @@ public function configureManageOptions(OptionsResolver $resolver)
{
}
/**
* {@inheritDoc}
*/
@@ -165,7 +159,6 @@ public function setColumnCount($columnCount)
$this->columnCount = $columnCount;
}
/**
* @param BlockInterface $block
*
@@ -20,10 +20,6 @@ class ContainerBlockService extends AbstractBlockService implements BlockService
{
protected $wrapper = "container";
/** @var string */
protected $view = 'OpiferContentBundle:Block:Layout/layout.html.twig';
/**
* {@inheritdoc}
*/
@@ -156,5 +152,4 @@ public function setWrapper($wrapper)
{
$this->wrapper = $wrapper;
}
}
}
@@ -9,22 +9,10 @@
use Opifer\ContentBundle\Model\BlockInterface;
/**
* Class HtmlBlockService
*
* @package Opifer\ContentBundle\Block
* HTML Block Service
*/
class HtmlBlockService extends AbstractBlockService implements BlockServiceInterface, ToolsetMemberInterface
{
protected $view = 'OpiferContentBundle:Block:Content/html.html.twig';
/**
* {@inheritDoc}
*/
public function getName(BlockInterface $block = null)
{
return 'Content';
}
/**
* {@inheritdoc}
*/
@@ -63,4 +51,4 @@ public function getTool()
return $tool;
}
}
}
Oops, something went wrong.

0 comments on commit f124e2e

Please sign in to comment.