Skip to content

Commit

Permalink
Deprecate BaseBlockService and BlockAdminServiceInterface (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 authored and OskarStark committed Aug 23, 2016
1 parent afa6ead commit da01e13
Show file tree
Hide file tree
Showing 16 changed files with 385 additions and 254 deletions.
27 changes: 8 additions & 19 deletions Block/AbstractBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,19 @@

namespace Sonata\BlockBundle\Block;

use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
@trigger_error(
'This class is deprecated since 3.x and will be removed with the 4.0 release.'.
'Use '.__NAMESPACE__.'\Block\Service\AbstractBlockService instead.',
E_USER_DEPRECATED
);

/**
* Class AbstractBlockService.
*
* @author Sullivan Senechal <soullivaneuh@gmail.com>
*
* @deprecated since 3.x, to be removed with 4.0
*/
abstract class AbstractBlockService implements BlockServiceInterface
abstract class AbstractBlockService extends \Sonata\BlockBundle\Block\Service\AbstractBlockService
{
/**
* {@inheritdoc}
*/
public function setDefaultSettings(OptionsResolverInterface $resolver)
{
$this->configureSettings($resolver);
}

/**
* Define the default options for the block.
*
* @param OptionsResolver $resolver
*/
public function configureSettings(OptionsResolver $resolver)
{
}
}
202 changes: 10 additions & 192 deletions Block/BaseBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,204 +11,22 @@

namespace Sonata\BlockBundle\Block;

use Sonata\AdminBundle\Form\FormMapper;
use Sonata\BlockBundle\Model\BlockInterface;
use Sonata\CoreBundle\Model\Metadata;
use Sonata\CoreBundle\Validator\ErrorElement;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\HttpFoundation\Response;
use Sonata\BlockBundle\Block\Service\AbstractAdminBlockService;

@trigger_error(
'This class is deprecated since 3.x and will be removed with the 4.0 release.'.
'Use '.__NAMESPACE__.'\Block\Service\AbstractBlockService instead.',
E_USER_DEPRECATED
);

/**
* BaseBlockService.
*
*
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* @deprecated since 3.x, to be removed with 4.0
*/
abstract class BaseBlockService extends AbstractBlockService implements BlockAdminServiceInterface
abstract class BaseBlockService extends AbstractAdminBlockService implements BlockAdminServiceInterface
{
/**
* @var string
*/
protected $name;

/**
* @var EngineInterface
*/
protected $templating;

/**
* @param string $name
* @param EngineInterface $templating
*/
public function __construct($name, EngineInterface $templating)
{
$this->name = $name;
$this->templating = $templating;
}

/**
* Returns a Response object than can be cacheable.
*
* @param string $view
* @param array $parameters
* @param Response $response
*
* @return Response
*/
public function renderResponse($view, array $parameters = array(), Response $response = null)
{
return $this->getTemplating()->renderResponse($view, $parameters, $response);
}

/**
* Returns a Response object that cannot be cacheable, this must be used if the Response is related to the user.
* A good solution to make the page cacheable is to configure the block to be cached with javascript ...
*
* @param string $view
* @param array $parameters
* @param Response $response
*
* @return Response
*/
public function renderPrivateResponse($view, array $parameters = array(), Response $response = null)
{
return $this->renderResponse($view, $parameters, $response)
->setTtl(0)
->setPrivate()
;
}

/**
* {@inheritdoc}
*/
public function getName()
{
return $this->name;
}

/**
* {@inheritdoc}
*/
public function getTemplating()
{
return $this->templating;
}

/**
* {@inheritdoc}
*/
public function buildCreateForm(FormMapper $formMapper, BlockInterface $block)
{
$this->buildEditForm($formMapper, $block);
}

/**
* {@inheritdoc}
*/
public function getCacheKeys(BlockInterface $block)
{
return array(
'block_id' => $block->getId(),
'updated_at' => $block->getUpdatedAt() ? $block->getUpdatedAt()->format('U') : strtotime('now'),
);
}

/**
* @param BlockInterface $block
*/
public function prePersist(BlockInterface $block)
{
}

/**
* @param BlockInterface $block
*/
public function postPersist(BlockInterface $block)
{
}

/**
* @param BlockInterface $block
*/
public function preUpdate(BlockInterface $block)
{
}

/**
* @param BlockInterface $block
*/
public function postUpdate(BlockInterface $block)
{
}

/**
* @param BlockInterface $block
*/
public function preRemove(BlockInterface $block)
{
}

/**
* @param BlockInterface $block
*/
public function postRemove(BlockInterface $block)
{
}

/**
* {@inheritdoc}
*/
public function load(BlockInterface $block)
{
}

/**
* {@inheritdoc}
*/
public function getJavascripts($media)
{
return array();
}

/**
* {@inheritdoc}
*/
public function getStylesheets($media)
{
return array();
}

/**
* {@inheritdoc}
*/
public function execute(BlockContextInterface $blockContext, Response $response = null)
{
return $this->renderResponse($blockContext->getTemplate(), array(
'block_context' => $blockContext,
'block' => $blockContext->getBlock(),
), $response);
}

/**
* {@inheritdoc}
*/
public function buildEditForm(FormMapper $form, BlockInterface $block)
{
}

/**
* @param ErrorElement $errorElement
* @param BlockInterface $block
*/
public function validateBlock(ErrorElement $errorElement, BlockInterface $block)
{
}

/**
* {@inheritdoc}
*/
public function getBlockMetadata($code = null)
{
return new Metadata($this->getName(), (!is_null($code) ? $code : $this->getName()), false, 'SonataBlockBundle', array('class' => 'fa fa-file'));
}
}
40 changes: 11 additions & 29 deletions Block/BlockAdminServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,17 @@

namespace Sonata\BlockBundle\Block;

use Sonata\AdminBundle\Form\FormMapper;
use Sonata\BlockBundle\Model\BlockInterface;
use Sonata\CoreBundle\Model\MetadataInterface;
use Sonata\CoreBundle\Validator\ErrorElement;
use Sonata\BlockBundle\Block\Service\AdminBlockServiceInterface;

interface BlockAdminServiceInterface
{
/**
* @param FormMapper $form
* @param BlockInterface $block
*/
public function buildEditForm(FormMapper $form, BlockInterface $block);

/**
* @param FormMapper $form
* @param BlockInterface $block
*/
public function buildCreateForm(FormMapper $form, BlockInterface $block);

/**
* @param ErrorElement $errorElement
* @param BlockInterface $block
*/
public function validateBlock(ErrorElement $errorElement, BlockInterface $block);
@trigger_error(
'This class is deprecated since 3.x and will be removed with the 4.0 release.'.
'Use '.__NAMESPACE__.'\Block\Service\AdminBlockServiceInterface instead.',
E_USER_DEPRECATED
);

/**
* @param string|null $code
*
* @return MetadataInterface
*/
public function getBlockMetadata($code = null);
/**
* @deprecated since 3.x, to be removed with 4.0
*/
interface BlockAdminServiceInterface extends AdminBlockServiceInterface
{
}
2 changes: 2 additions & 0 deletions Block/BlockServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

/**
* Interface BlockServiceInterface.
*
* @deprecated since 3.x, to be removed with 4.0
*/
interface BlockServiceInterface
{
Expand Down
Loading

0 comments on commit da01e13

Please sign in to comment.