Issue #2342949 by rpayanm | larowlan: Cleanup BlockContentBlock.
parent
81e675a570
commit
f99eb0495b
|
@ -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. <a href="!url">Add custom block</a>.', array(
|
||||
'%uuid' => $uuid,
|
||||
'!url' => url('block/add')
|
||||
'!url' => $this->urlGenerator->generate('block_content.add_page')
|
||||
)),
|
||||
'#access' => $this->account->hasPermission('administer blocks')
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue