Skip to content
Snippets Groups Projects
Commit 7f2710be authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2315333 by tim.plunkett: Move block plugin code out of block.module.

parent f3c0bc05
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Showing
with 56 additions and 51 deletions
......@@ -274,6 +274,9 @@ services:
entity.form_builder:
class: Drupal\Core\Entity\EntityFormBuilder
arguments: ['@entity.manager', '@form_builder']
plugin.manager.block:
class: Drupal\Core\Block\BlockManager
parent: default_plugin_manager
plugin.manager.field.field_type:
class: Drupal\Core\Field\FieldTypePluginManager
arguments: ['@container.namespaces', '@cache.discovery', '@module_handler']
......
......@@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\block\Annotation\Block.
* Contains \Drupal\Core\Block\Annotation\Block.
*/
namespace Drupal\block\Annotation;
namespace Drupal\Core\Block\Annotation;
use Drupal\Component\Annotation\Plugin;
......
......@@ -2,11 +2,12 @@
/**
* @file
* Contains \Drupal\block\BlockBase.
* Contains \Drupal\Core\Block\BlockBase.
*/
namespace Drupal\block;
namespace Drupal\Core\Block;
use Drupal\block\BlockInterface;
use Drupal\block\Event\BlockConditionContextEvent;
use Drupal\block\Event\BlockEvents;
use Drupal\Component\Plugin\ContextAwarePluginInterface;
......@@ -198,7 +199,7 @@ protected function blockAccess(AccountInterface $account) {
* BlockBase::blockForm(). Most block plugins should not override this
* method unless they need to alter the generic form elements.
*
* @see \Drupal\block\BlockBase::blockForm()
* @see \Drupal\Core\Block\BlockBase::blockForm()
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$definition = $this->getPluginDefinition();
......@@ -335,7 +336,7 @@ public function blockForm($form, FormStateInterface $form_state) {
* Most block plugins should not override this method. To add validation
* for a specific block type, override BlockBase::blockValdiate().
*
* @see \Drupal\block\BlockBase::blockValidate()
* @see \Drupal\Core\Block\BlockBase::blockValidate()
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
// Remove the admin_label form item element value so it will not persist.
......@@ -369,7 +370,7 @@ public function blockValidate($form, FormStateInterface $form_state) {}
* Most block plugins should not override this method. To add submission
* handling for a specific block type, override BlockBase::blockSubmit().
*
* @see \Drupal\block\BlockBase::blockSubmit()
* @see \Drupal\Core\Block\BlockBase::blockSubmit()
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
// Process the block's submission handling if no errors occurred only.
......
......@@ -2,16 +2,15 @@
/**
* @file
* Contains \Drupal\block\BlockManager.
* Contains \Drupal\Core\Block\BlockManager.
*/
namespace Drupal\block;
namespace Drupal\Core\Block;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\Context\ContextAwarePluginManagerTrait;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
/**
......@@ -19,7 +18,7 @@
*
* @todo Add documentation to this class.
*
* @see \Drupal\block\BlockPluginInterface
* @see \Drupal\Core\Block\BlockPluginInterface
*/
class BlockManager extends DefaultPluginManager implements BlockManagerInterface {
......@@ -34,7 +33,7 @@ class BlockManager extends DefaultPluginManager implements BlockManagerInterface
protected $moduleData;
/**
* Constructs a new \Drupal\block\BlockManager object.
* Constructs a new \Drupal\Core\Block\BlockManager object.
*
* @param \Traversable $namespaces
* An object that implements \Traversable which contains the root paths
......@@ -43,15 +42,12 @@ class BlockManager extends DefaultPluginManager implements BlockManagerInterface
* Cache backend instance to use.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler to invoke the alter hook with.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The translation manager.
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, TranslationInterface $string_translation) {
parent::__construct('Plugin/Block', $namespaces, $module_handler, 'Drupal\block\Annotation\Block');
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/Block', $namespaces, $module_handler, 'Drupal\Core\Block\Annotation\Block');
$this->alterInfo('block');
$this->setCacheBackend($cache_backend, 'block_plugins');
$this->stringTranslation = $string_translation;
}
/**
......
......@@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\block\BlockManagerInterface.
* Contains \Drupal\Core\Block\BlockManagerInterface.
*/
namespace Drupal\block;
namespace Drupal\Core\Block;
use Drupal\Core\Plugin\Context\ContextAwarePluginManagerInterface;
......
......@@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\block\BlockPluginInterface.
* Contains \Drupal\Core\Block\BlockPluginInterface.
*/
namespace Drupal\block;
namespace Drupal\Core\Block;
use Drupal\Component\Plugin\Context\ContextInterface;
use Drupal\Component\Plugin\DerivativeInspectionInterface;
......@@ -109,8 +109,8 @@ public function blockForm($form, FormStateInterface $form_state);
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @see \Drupal\block\BlockPluginInterface::blockForm()
* @see \Drupal\block\BlockPluginInterface::blockSubmit()
* @see \Drupal\Core\Block\BlockPluginInterface::blockForm()
* @see \Drupal\Core\Block\BlockPluginInterface::blockSubmit()
*/
public function blockValidate($form, FormStateInterface $form_state);
......@@ -126,8 +126,8 @@ public function blockValidate($form, FormStateInterface $form_state);
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @see \Drupal\block\BlockPluginInterface::blockForm()
* @see \Drupal\block\BlockPluginInterface::blockValidate()
* @see \Drupal\Core\Block\BlockPluginInterface::blockForm()
* @see \Drupal\Core\Block\BlockPluginInterface::blockValidate()
*/
public function blockSubmit($form, FormStateInterface $form_state);
......
......@@ -131,4 +131,12 @@ public function getBaseThemes(array $themes, $theme);
*/
public function getName($theme);
/**
* Returns the default theme.
*
* @return string
* The default theme.
*/
public function getDefault();
}
......@@ -10,7 +10,7 @@
use Drupal\Component\Utility\NestedArray;
use Drupal\aggregator\FeedStorageInterface;
use Drupal\aggregator\ItemStorageInterface;
use Drupal\block\BlockBase;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Entity\Query\QueryInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
......
......@@ -17,14 +17,14 @@
*
* To define a block in a module you need to:
* - Define a Block plugin by creating a new class that implements the
* \Drupal\block\BlockPluginInterface, in namespace Plugin\Block under your
* \Drupal\Core\Block\BlockPluginInterface, in namespace Plugin\Block under your
* module namespace. For more information about creating plugins, see the
* @link plugin_api Plugin API topic. @endlink
* - Usually you will want to extend the \Drupal\block\BlockBase class, which
* - Usually you will want to extend the \Drupal\Core\Block\BlockBase class, which
* provides a common configuration form and utility methods for getting and
* setting configuration in the block configuration entity.
* - Block plugins use the annotations defined by
* \Drupal\block\Annotation\Block. See the
* \Drupal\Core\Block\Annotation\Block. See the
* @link annotation Annotations topic @endlink for more information about
* annotations.
*
......@@ -61,7 +61,7 @@
*/
/**
* Alter the result of \Drupal\block\BlockBase::build().
* Alter the result of \Drupal\Core\Block\BlockBase::build().
*
* This hook is called after the content has been assembled in a structured
* array and may be used for doing processing which requires that the complete
......@@ -81,7 +81,7 @@
* A renderable array of data, as returned from the build() implementation of
* the plugin that defined the block:
* - #title: The default localized title of the block.
* @param \Drupal\block\BlockPluginInterface $block
* @param \Drupal\Core\Block\BlockPluginInterface $block
* The block plugin instance.
*
* @see hook_block_view_BASE_BLOCK_ID_alter()
......@@ -89,7 +89,7 @@
*
* @ingroup block_api
*/
function hook_block_view_alter(array &$build, \Drupal\block\BlockPluginInterface $block) {
function hook_block_view_alter(array &$build, \Drupal\Core\Block\BlockPluginInterface $block) {
// Remove the contextual links on all blocks that provide them.
if (isset($build['#contextual_links'])) {
unset($build['#contextual_links']);
......@@ -111,7 +111,7 @@ function hook_block_view_alter(array &$build, \Drupal\block\BlockPluginInterface
* A renderable array of data, as returned from the build() implementation of
* the plugin that defined the block:
* - #title: The default localized title of the block.
* @param \Drupal\block\BlockPluginInterface $block
* @param \Drupal\Core\Block\BlockPluginInterface $block
* The block plugin instance.
*
* @see hook_block_view_alter()
......@@ -119,7 +119,7 @@ function hook_block_view_alter(array &$build, \Drupal\block\BlockPluginInterface
*
* @ingroup block_api
*/
function hook_block_view_BASE_BLOCK_ID_alter(array &$build, \Drupal\block\BlockPluginInterface $block) {
function hook_block_view_BASE_BLOCK_ID_alter(array &$build, \Drupal\Core\Block\BlockPluginInterface $block) {
// Change the title of the specific block.
$build['#title'] = t('New title of the block');
}
......
services:
plugin.manager.block:
class: Drupal\block\BlockManager
arguments: ['@container.namespaces', '@cache.discovery', '@module_handler', '@string_translation']
theme.negotiator.block.admin_demo:
class: Drupal\block\Theme\AdminDemoNegotiator
tags:
......
......@@ -27,7 +27,7 @@ interface BlockInterface extends ConfigEntityInterface {
/**
* Returns the plugin instance.
*
* @return \Drupal\block\BlockPluginInterface
* @return \Drupal\Core\Block\BlockPluginInterface
* The plugin instance for this block.
*/
public function getPlugin();
......
......@@ -7,7 +7,7 @@
namespace Drupal\block;
use Drupal\block\BlockManagerInterface;
use Drupal\Core\Block\BlockManagerInterface;
use Drupal\Component\Serialization\Json;
use Drupal\Component\Utility\String;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
......@@ -50,7 +50,7 @@ class BlockListBuilder extends ConfigEntityListBuilder implements FormInterface
/**
* The block manager.
*
* @var \Drupal\block\BlockManagerInterface
* @var \Drupal\Core\Block\BlockManagerInterface
*/
protected $blockManager;
......@@ -61,7 +61,7 @@ class BlockListBuilder extends ConfigEntityListBuilder implements FormInterface
* The entity type definition.
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
* The entity storage class.
* @param \Drupal\block\BlockManagerInterface $block_manager
* @param \Drupal\Core\Block\BlockManagerInterface $block_manager
* The block manager.
*/
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, BlockManagerInterface $block_manager) {
......
......@@ -45,7 +45,7 @@ public function __construct(PluginManagerInterface $manager, $instance_id, array
/**
* {@inheritdoc}
*
* @return \Drupal\block\BlockPluginInterface
* @return \Drupal\Core\Block\BlockPluginInterface
*/
public function &get($instance_id) {
return parent::get($instance_id);
......
......@@ -7,7 +7,7 @@
namespace Drupal\block\Controller;
use Drupal\block\BlockManagerInterface;
use Drupal\Core\Block\BlockManagerInterface;
use Drupal\Component\Utility\String;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -22,14 +22,14 @@ class CategoryAutocompleteController implements ContainerInjectionInterface {
/**
* The block manager.
*
* @var \Drupal\block\BlockManagerInterface
* @var \Drupal\Core\Block\BlockManagerInterface
*/
protected $blockManager;
/**
* Constructs a new CategoryAutocompleteController.
*
* @param \Drupal\block\BlockManagerInterface $block_manager
* @param \Drupal\Core\Block\BlockManagerInterface $block_manager
* The block manager.
*/
public function __construct(BlockManagerInterface $block_manager) {
......
......@@ -30,7 +30,7 @@ public function __construct(ConditionPluginBag $conditions) {
}
/**
* @return \Drupal\block\BlockPluginInterface
* @return \Drupal\Core\Block\BlockPluginInterface
*/
public function getConditions() {
return $this->conditions;
......
......@@ -15,7 +15,7 @@ final class BlockEvents {
/**
* Name of the event when gathering condition context for a block plugin.
*
* @see \Drupal\block\BlockBase::getConditionContexts()
* @see \Drupal\Core\Block\BlockBase::getConditionContexts()
* @see \Drupal\block\Event\BlockConditionContextEvent
*/
const CONDITION_CONTEXT = 'block.condition_context';
......
......@@ -47,7 +47,7 @@ class BlockConfigSchemaTest extends KernelTestBase {
/**
* The block manager.
*
* @var \Drupal\block\BlockManagerInterface
* @var \Drupal\Core\Block\BlockManagerInterface
*/
protected $blockManager;
......
......@@ -51,7 +51,7 @@ public function testBlockInterface() {
'display_message' => 'no message set',
);
// Initial configuration of the block at construction time.
/** @var $display_block \Drupal\block\BlockPluginInterface */
/** @var $display_block \Drupal\Core\Block\BlockPluginInterface */
$display_block = $manager->createInstance('test_block_instantiation', $configuration);
$this->assertIdentical($display_block->getConfiguration(), $expected_configuration, 'The block was configured correctly.');
......
......@@ -5,7 +5,7 @@
* Provide test blocks.
*/
use Drupal\block\BlockPluginInterface;
use Drupal\Core\Block\BlockPluginInterface;
/**
* Implements hook_block_alter().
......
......@@ -7,7 +7,7 @@
namespace Drupal\block_test\Plugin\Block;
use Drupal\block\BlockBase;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment