diff --git a/core/modules/block/block.services.yml b/core/modules/block/block.services.yml index 5b6e521..fe20e4a 100644 --- a/core/modules/block/block.services.yml +++ b/core/modules/block/block.services.yml @@ -9,4 +9,4 @@ services: - { name: event_subscriber } block.repository: class: Drupal\block\BlockRepository - arguments: ['@entity.manager', '@theme.manager'] + arguments: ['@entity.manager', '@theme.manager', '@context.handler'] diff --git a/core/modules/block/src/BlockForm.php b/core/modules/block/src/BlockForm.php index 609c2d6..915d16b 100644 --- a/core/modules/block/src/BlockForm.php +++ b/core/modules/block/src/BlockForm.php @@ -334,8 +334,8 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $settings = (new FormState())->setValues($form_state->getValue('settings')); // Call the plugin submit handler. + $entity->getPlugin()->submitConfigurationForm($form, $settings); $block = $entity->getPlugin(); - $block->submitConfigurationForm($form, $settings); // If this block is context-aware, set the context mapping. if ($block instanceof ContextAwarePluginInterface && $block->getContextDefinitions()) { $context_mapping = $settings->getValue('context_mapping', []); @@ -362,7 +362,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $entity->getVisibilityConditions()->addInstanceId($condition_id, $condition_configuration); } - // Save the updated block. + // Save the settings of the plugin. $entity->save(); drupal_set_message($this->t('The block configuration has been saved.')); diff --git a/core/modules/block/src/BlockListBuilder.php b/core/modules/block/src/BlockListBuilder.php index e2e4ae7..b92e7ae 100644 --- a/core/modules/block/src/BlockListBuilder.php +++ b/core/modules/block/src/BlockListBuilder.php @@ -88,8 +88,7 @@ public static function createInstance(ContainerInterface $container, EntityTypeI $entity_type, $container->get('entity.manager')->getStorage($entity_type->id()), $container->get('theme.manager'), - $container->get('form_builder'), - $container->get('context.repository') + $container->get('form_builder') ); } diff --git a/core/modules/block/src/BlockRepository.php b/core/modules/block/src/BlockRepository.php index 103557b..9d56fde 100644 --- a/core/modules/block/src/BlockRepository.php +++ b/core/modules/block/src/BlockRepository.php @@ -9,6 +9,7 @@ use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Plugin\Context\ContextHandlerInterface; use Drupal\Core\Theme\ThemeManagerInterface; /** @@ -37,10 +38,13 @@ class BlockRepository implements BlockRepositoryInterface { * The entity manager. * @param \Drupal\Core\Theme\ThemeManagerInterface $theme_manager * The theme manager. + * @param \Drupal\Core\Plugin\Context\ContextHandlerInterface $context_handler + * The plugin context handler. */ - public function __construct(EntityManagerInterface $entity_manager, ThemeManagerInterface $theme_manager) { + public function __construct(EntityManagerInterface $entity_manager, ThemeManagerInterface $theme_manager, ContextHandlerInterface $context_handler) { $this->blockStorage = $entity_manager->getStorage('block'); $this->themeManager = $theme_manager; + $this->contextHandler = $context_handler; } /** diff --git a/core/modules/block/src/Controller/BlockLibraryController.php b/core/modules/block/src/Controller/BlockLibraryController.php index fed0ece..0f6c965 100644 --- a/core/modules/block/src/Controller/BlockLibraryController.php +++ b/core/modules/block/src/Controller/BlockLibraryController.php @@ -31,6 +31,13 @@ class BlockLibraryController extends ControllerBase { protected $blockManager; /** + * The context repository. + * + * @var \Drupal\Core\Plugin\Context\LazyContextRepository + */ + protected $contextRepository; + + /** * The route match. * * @var \Drupal\Core\Routing\RouteMatchInterface @@ -45,23 +52,18 @@ class BlockLibraryController extends ControllerBase { protected $localActionManager; /** - * The context repository. - * - * @var \Drupal\Core\Plugin\Context\LazyContextRepository - */ - protected $contextRepository; - - /** * Constructs a BlockLibraryController object. * * @param \Drupal\Core\Block\BlockManagerInterface $block_manager * The block manager. + * @param \Drupal\Core\Plugin\Context\LazyContextRepository $context_repository + * The context repository. * @param \Drupal\Core\Routing\RouteMatchInterface $route_match * The current route match. * @param \Drupal\Core\Menu\LocalActionManagerInterface $local_action_manager * The local action manager. */ - public function __construct(BlockManagerInterface $block_manager, RouteMatchInterface $route_match, LocalActionManagerInterface $local_action_manager, LazyContextRepository $context_repository) { + public function __construct(BlockManagerInterface $block_manager, LazyContextRepository $context_repository, RouteMatchInterface $route_match, LocalActionManagerInterface $local_action_manager) { $this->blockManager = $block_manager; $this->routeMatch = $route_match; $this->localActionManager = $local_action_manager; @@ -74,9 +76,9 @@ public function __construct(BlockManagerInterface $block_manager, RouteMatchInte public static function create(ContainerInterface $container) { return new static( $container->get('plugin.manager.block'), + $container->get('context.repository'), $container->get('current_route_match'), - $container->get('plugin.manager.menu.local_action'), - $container->get('context.repository') + $container->get('plugin.manager.menu.local_action') ); } diff --git a/core/modules/block/src/Tests/BlockUiTest.php b/core/modules/block/src/Tests/BlockUiTest.php index 2206158..d3bb947 100644 --- a/core/modules/block/src/Tests/BlockUiTest.php +++ b/core/modules/block/src/Tests/BlockUiTest.php @@ -208,7 +208,6 @@ public function testContextAwareUnsatisfiedBlocks() { ':title' => 'Test context-aware block', ':category' => 'Block test', ':href' => 'admin/structure/block/add/test_context_aware_unsatisfied/classy', - ]; $pattern = '//tr[.//td/div[text()=:title] and .//td[text()=:category] and .//td//a[contains(@href, :href)]]'; diff --git a/core/modules/block/tests/src/Unit/BlockRepositoryTest.php b/core/modules/block/tests/src/Unit/BlockRepositoryTest.php index 83747de..aab11fe 100644 --- a/core/modules/block/tests/src/Unit/BlockRepositoryTest.php +++ b/core/modules/block/tests/src/Unit/BlockRepositoryTest.php @@ -35,6 +35,11 @@ class BlockRepositoryTest extends UnitTestCase { protected $theme; /** + * @var \Drupal\Core\Plugin\Context\ContextHandlerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $contextHandler; + + /** * {@inheritdoc} */ protected function setUp() { @@ -59,13 +64,14 @@ protected function setUp() { ->method('getActiveTheme') ->will($this->returnValue($active_theme)); + $this->contextHandler = $this->getMock('Drupal\Core\Plugin\Context\ContextHandlerInterface'); $this->blockStorage = $this->getMock('Drupal\Core\Entity\EntityStorageInterface'); $entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface'); $entity_manager->expects($this->any()) ->method('getStorage') ->willReturn($this->blockStorage); - $this->blockRepository = new BlockRepository($entity_manager, $theme_manager); + $this->blockRepository = new BlockRepository($entity_manager, $theme_manager, $this->contextHandler); } /** diff --git a/core/tests/Drupal/Tests/Core/Annotation/ContextDefinitionTest.php b/core/tests/Drupal/Tests/Core/Annotation/ContextDefinitionTest.php index 7f8382f..ff313f2 100644 --- a/core/tests/Drupal/Tests/Core/Annotation/ContextDefinitionTest.php +++ b/core/tests/Drupal/Tests/Core/Annotation/ContextDefinitionTest.php @@ -41,7 +41,6 @@ public function testContextDefinitionAnnotation() { $values = [ 'value' => 'entity:node', - //'label' => new Translation(['value' => 'test']), 'label' => 'test', 'description' => 'test', ];