Commit 58d8e35c authored by alexpott's avatar alexpott

Issue #2003058 by ashwinikumar, ebeyrent, DmitryDrozdik, benjy: Replace...

Issue #2003058 by ashwinikumar, ebeyrent, DmitryDrozdik, benjy: Replace drupal_container() with Drupal::service() in the block module.
parent f325f63c
......@@ -10,6 +10,10 @@
use Drupal\block\BlockBase;
use Drupal\Component\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\block\Plugin\Type\BlockManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Defines a generic custom block type.
......@@ -21,7 +25,55 @@
* derivative = "Drupal\custom_block\Plugin\Derivative\CustomBlock"
* )
*/
class CustomBlockBlock extends BlockBase {
class CustomBlockBlock extends BlockBase implements ContainerFactoryPluginInterface {
/**
* The Plugin Block Manager.
*
* @var \Drupal\block\Plugin\Type\BlockManager.
*/
protected $blockManager;
/**
* The Module Handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface.
*/
protected $moduleHandler;
/**
* Constructs a new CustomBlockBlock.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin ID for the plugin instance.
* @param array $plugin_definition
* The plugin implementation definition.
* @param \Drupal\block\Plugin\Type\BlockManager
* The Plugin Block Manager.
* @param \Drupal\Core\Extension\ModuleHandlerInterface
* The Module Handler.
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, BlockManager $block_manager, ModuleHandlerInterface $module_handler) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->blockManager = $block_manager;
$this->moduleHandler = $module_handler;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, array $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('plugin.manager.block'),
$container->get('module_handler')
);
}
/**
* Overrides \Drupal\block\BlockBase::settings().
......@@ -61,8 +113,8 @@ public function blockForm($form, &$form_state) {
*/
public function blockSubmit($form, &$form_state) {
// Invalidate the block cache to update custom block-based derivatives.
if (module_exists('block')) {
drupal_container()->get('plugin.manager.block')->clearCachedDefinitions();
if ($this->moduleHandler->moduleExists('block')) {
$this->blockManager->clearCachedDefinitions();
}
}
......
......@@ -8,13 +8,47 @@
namespace Drupal\block;
use Drupal\Core\Entity\EntityAccessController;
use Drupal\Core\Entity\EntityControllerInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Path\AliasManagerInterface;
use Drupal\Component\Utility\Unicode;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a Block access controller.
*/
class BlockAccessController extends EntityAccessController {
class BlockAccessController extends EntityAccessController implements EntityControllerInterface {
/**
* The node grant storage.
*
* @var \Drupal\Core\Path\AliasManagerInterface
*/
protected $aliasManager;
/**
* Constructs a BlockAccessController object.
*
* @param string $entity_type
* The entity type of the access controller instance.
* @param \Drupal\Core\Path\AliasManagerInterface $alias_manager
* The alias manager.
*/
public function __construct($entity_type, AliasManagerInterface $alias_manager) {
parent::__construct($entity_type);
$this->aliasManager = $alias_manager;
}
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) {
return new static(
$entity_type,
$container->get('path.alias_manager')
);
}
/**
* {@inheritdoc}
......@@ -64,7 +98,7 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A
if ($visibility['path']['visibility'] < BLOCK_VISIBILITY_PHP) {
// Compare the lowercase path alias (if any) and internal path.
$path = current_path();
$path_alias = drupal_strtolower(drupal_container()->get('path.alias_manager')->getPathAlias($path));
$path_alias = Unicode::strtolower($this->aliasManager->getPathAlias($path));
$page_match = drupal_match_path($path_alias, $pages) || (($path != $path_alias) && drupal_match_path($path, $pages));
// When $block->visibility has a value of 0
// (BLOCK_VISIBILITY_NOTLISTED), the block is displayed on all pages
......
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