diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Block/CustomBlockBlock.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Block/CustomBlockBlock.php index 0d17fa1e9400516e9e9c10dd556562c9d13f1831..c4174c8e8fc9d0130895542b5e4ae605477badd1 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Block/CustomBlockBlock.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Block/CustomBlockBlock.php @@ -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(); } } diff --git a/core/modules/block/lib/Drupal/block/BlockAccessController.php b/core/modules/block/lib/Drupal/block/BlockAccessController.php index a4827e5612265975d11b2b959a5dfc0217c52df4..26716c2bd7f031ec4bfd70b9b248485d99da40ff 100644 --- a/core/modules/block/lib/Drupal/block/BlockAccessController.php +++ b/core/modules/block/lib/Drupal/block/BlockAccessController.php @@ -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