Issue #2342949 by rpayanm | larowlan: Cleanup BlockContentBlock.

8.0.x
Alex Pott 2014-09-24 11:20:54 +01:00
parent 81e675a570
commit f99eb0495b
1 changed files with 8 additions and 6 deletions

View File

@ -9,11 +9,11 @@ namespace Drupal\block_content\Plugin\Block;
use Drupal\Core\Block\BlockBase; use Drupal\Core\Block\BlockBase;
use Drupal\Core\Block\BlockManagerInterface; use Drupal\Core\Block\BlockManagerInterface;
use Drupal\Core\Entity\EntityManager;
use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
@ -75,13 +75,14 @@ class BlockContentBlock extends BlockBase implements ContainerFactoryPluginInter
* @param \Drupal\Core\Session\AccountInterface $account * @param \Drupal\Core\Session\AccountInterface $account
* The account for which view access should be checked. * The account for which view access should be checked.
*/ */
public function __construct(array $configuration, $plugin_id, $plugin_definition, BlockManagerInterface $block_manager, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, AccountInterface $account) { public function __construct(array $configuration, $plugin_id, $plugin_definition, BlockManagerInterface $block_manager, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, AccountInterface $account, UrlGeneratorInterface $url_generator) {
parent::__construct($configuration, $plugin_id, $plugin_definition); parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->blockManager = $block_manager; $this->blockManager = $block_manager;
$this->entityManager = $entity_manager; $this->entityManager = $entity_manager;
$this->moduleHandler = $module_handler; $this->moduleHandler = $module_handler;
$this->account = $account; $this->account = $account;
$this->urlGenerator = $url_generator;
} }
/** /**
@ -95,7 +96,8 @@ class BlockContentBlock extends BlockBase implements ContainerFactoryPluginInter
$container->get('plugin.manager.block'), $container->get('plugin.manager.block'),
$container->get('entity.manager'), $container->get('entity.manager'),
$container->get('module_handler'), $container->get('module_handler'),
$container->get('current_user') $container->get('current_user'),
$container->get('url_generator')
); );
} }
@ -149,14 +151,14 @@ class BlockContentBlock extends BlockBase implements ContainerFactoryPluginInter
*/ */
public function build() { public function build() {
$uuid = $this->getDerivativeId(); $uuid = $this->getDerivativeId();
if ($block = entity_load_by_uuid('block_content', $uuid)) { if ($block = $this->entityManager->loadEntityByUuid('block_content', $uuid)) {
return entity_view($block, $this->configuration['view_mode']); return $this->entityManager->getViewBuilder($block->getEntityTypeId())->view($block, $this->configuration['view_mode']);
} }
else { else {
return array( return array(
'#markup' => t('Block with uuid %uuid does not exist. <a href="!url">Add custom block</a>.', array( '#markup' => t('Block with uuid %uuid does not exist. <a href="!url">Add custom block</a>.', array(
'%uuid' => $uuid, '%uuid' => $uuid,
'!url' => url('block/add') '!url' => $this->urlGenerator->generate('block_content.add_page')
)), )),
'#access' => $this->account->hasPermission('administer blocks') '#access' => $this->account->hasPermission('administer blocks')
); );