Commit f99eb049 authored by alexpott's avatar alexpott

Issue #2342949 by rpayanm | larowlan: Cleanup BlockContentBlock.

parent 81e675a5
......@@ -9,11 +9,11 @@
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 @@ public static function create(ContainerInterface $container, array $configuratio
$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 @@ public function blockSubmit($form, FormStateInterface $form_state) {
*/
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')
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment