From f99eb0495b5af93b957c81ea302d689c02bf78ec Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Wed, 24 Sep 2014 11:20:54 +0100 Subject: [PATCH] Issue #2342949 by rpayanm | larowlan: Cleanup BlockContentBlock. --- .../src/Plugin/Block/BlockContentBlock.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/core/modules/block_content/src/Plugin/Block/BlockContentBlock.php b/core/modules/block_content/src/Plugin/Block/BlockContentBlock.php index 9e40c81efd9..3db1a1c2457 100644 --- a/core/modules/block_content/src/Plugin/Block/BlockContentBlock.php +++ b/core/modules/block_content/src/Plugin/Block/BlockContentBlock.php @@ -9,11 +9,11 @@ namespace Drupal\block_content\Plugin\Block; use Drupal\Core\Block\BlockBase; use Drupal\Core\Block\BlockManagerInterface; -use Drupal\Core\Entity\EntityManager; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\Core\Routing\UrlGeneratorInterface; use Drupal\Core\Session\AccountInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -75,13 +75,14 @@ class BlockContentBlock extends BlockBase implements ContainerFactoryPluginInter * @param \Drupal\Core\Session\AccountInterface $account * 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); $this->blockManager = $block_manager; $this->entityManager = $entity_manager; $this->moduleHandler = $module_handler; $this->account = $account; + $this->urlGenerator = $url_generator; } /** @@ -95,7 +96,8 @@ class BlockContentBlock extends BlockBase implements ContainerFactoryPluginInter $container->get('plugin.manager.block'), $container->get('entity.manager'), $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() { $uuid = $this->getDerivativeId(); - if ($block = entity_load_by_uuid('block_content', $uuid)) { - return entity_view($block, $this->configuration['view_mode']); + if ($block = $this->entityManager->loadEntityByUuid('block_content', $uuid)) { + return $this->entityManager->getViewBuilder($block->getEntityTypeId())->view($block, $this->configuration['view_mode']); } else { return array( '#markup' => t('Block with uuid %uuid does not exist. Add custom block.', array( '%uuid' => $uuid, - '!url' => url('block/add') + '!url' => $this->urlGenerator->generate('block_content.add_page') )), '#access' => $this->account->hasPermission('administer blocks') );