diff --git a/core/modules/block/block.module b/core/modules/block/block.module
index e65d07a..a7dd7dc 100644
--- a/core/modules/block/block.module
+++ b/core/modules/block/block.module
@@ -86,45 +86,6 @@ function block_page_top(array &$page_top) {
}
/**
- * Returns an array of block class instances by theme.
- *
- * @param $theme
- * The theme to rehash blocks for. If not provided, defaults to the currently
- * used theme.
- *
- * @return
- * Blocks currently exported by modules.
- */
-function _block_rehash($theme = NULL) {
- $theme = $theme ? $theme : \Drupal::config('system.theme')->get('default');
- $regions = system_region_list($theme);
- $blocks = entity_load_multiple_by_properties('block', array('theme' => $theme));
- foreach ($blocks as $block_id => $block) {
- // Remove any invalid block from the list.
- // @todo Remove this check as part of https://www.drupal.org/node/1776830.
- if (!$block->getPlugin()) {
- unset($blocks[$block_id]);
- continue;
- }
- $region = $block->getRegion();
- $status = $block->status();
- // Disable blocks in invalid regions.
- if (!empty($region) && $region != BlockInterface::BLOCK_REGION_NONE && !isset($regions[$region]) && $status) {
- drupal_set_message(t('The block %info was assigned to the invalid region %region and has been disabled.', array('%info' => $block_id, '%region' => $region)), 'warning');
- // Disabled blocks are moved into the BlockInterface::BLOCK_REGION_NONE
- // later so no need to move the block to another region.
- $block->disable()->save();
- }
- // Set region to none if not enabled.
- if (!$status && $region != BlockInterface::BLOCK_REGION_NONE) {
- $block->setRegion(BlockInterface::BLOCK_REGION_NONE);
- $block->save();
- }
- }
- return $blocks;
-}
-
-/**
* Initializes blocks for installed themes.
*
* @param $theme_list
@@ -177,9 +138,18 @@ function block_theme_initialize($theme) {
* Implements hook_rebuild().
*/
function block_rebuild() {
- foreach (\Drupal::service('theme_handler')->listInfo() as $name => $data) {
+ foreach (\Drupal::service('theme_handler')->listInfo() as $theme => $data) {
if ($data->status) {
- _block_rehash($name);
+ $regions = system_region_list($theme);
+ /** @var \Drupal\block\BlockInterface[] $blocks */
+ $blocks = entity_load_multiple_by_properties('block', ['theme' => $theme]);
+ foreach ($blocks as $block_id => $block) {
+ // Disable blocks in invalid regions.
+ if (!isset($regions[$block->getRegion()]) && $block->status()) {
+ drupal_set_message(t('The block %info was assigned to the invalid region %region and has been disabled.', ['%info' => $block_id, '%region' => $block->getRegion()]), 'warning');
+ $block->disable()->save();
+ }
+ }
}
}
}
diff --git a/core/modules/block/block.routing.yml b/core/modules/block/block.routing.yml
index 2f26a38..6c7ffef 100644
--- a/core/modules/block/block.routing.yml
+++ b/core/modules/block/block.routing.yml
@@ -25,6 +25,22 @@ entity.block.edit_form:
requirements:
_entity_access: 'block.update'
+entity.block.enable:
+ path: '/admin/structure/block/manage/{block}/enable'
+ defaults:
+ _controller: '\Drupal\block\Controller\BlockController::performOperation'
+ op: enable
+ requirements:
+ _entity_access: 'block.enable'
+
+entity.block.disable:
+ path: '/admin/structure/block/manage/{block}/disable'
+ defaults:
+ _controller: '\Drupal\block\Controller\BlockController::performOperation'
+ op: disable
+ requirements:
+ _entity_access: 'block.disable'
+
block.admin_display:
path: '/admin/structure/block'
defaults:
diff --git a/core/modules/block/css/block.admin.css b/core/modules/block/css/block.admin.css
index d9f32a2..71bf82c 100644
--- a/core/modules/block/css/block.admin.css
+++ b/core/modules/block/css/block.admin.css
@@ -50,6 +50,11 @@ a.block-demo-backlink:hover {
content: ':';
}
+.block-disabled {
+ color: #999;
+ background-color: #eee;
+}
+
/* Wide screens */
@media
screen and (min-width: 780px),
diff --git a/core/modules/block/src/BlockForm.php b/core/modules/block/src/BlockForm.php
index ac9406a..9f28c43 100644
--- a/core/modules/block/src/BlockForm.php
+++ b/core/modules/block/src/BlockForm.php
@@ -170,7 +170,7 @@ public function form(array $form, FormStateInterface $form_state) {
'#title' => $this->t('Region'),
'#description' => $this->t('Select the region where this block should be displayed.'),
'#default_value' => $entity->getRegion(),
- '#empty_value' => BlockInterface::BLOCK_REGION_NONE,
+ '#required' => TRUE,
'#options' => system_region_list($theme, REGIONS_VISIBLE),
'#prefix' => '
',
'#suffix' => '
',
diff --git a/core/modules/block/src/BlockInterface.php b/core/modules/block/src/BlockInterface.php
index 39ad9a9..48ce6e4 100644
--- a/core/modules/block/src/BlockInterface.php
+++ b/core/modules/block/src/BlockInterface.php
@@ -20,11 +20,6 @@
const BLOCK_LABEL_VISIBLE = 'visible';
/**
- * Denotes that a block is not enabled in any region and should not be shown.
- */
- const BLOCK_REGION_NONE = -1;
-
- /**
* Returns the plugin instance.
*
* @return \Drupal\Core\Block\BlockPluginInterface
diff --git a/core/modules/block/src/BlockListBuilder.php b/core/modules/block/src/BlockListBuilder.php
index aa669fa..83ada1a 100644
--- a/core/modules/block/src/BlockListBuilder.php
+++ b/core/modules/block/src/BlockListBuilder.php
@@ -15,8 +15,10 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
+use Drupal\Core\Form\FormBuilderInterface;
use Drupal\Core\Form\FormInterface;
use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Theme\ThemeManagerInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
@@ -29,13 +31,6 @@
class BlockListBuilder extends ConfigEntityListBuilder implements FormInterface {
/**
- * The regions containing the blocks.
- *
- * @var array
- */
- protected $regions;
-
- /**
* The theme containing the blocks.
*
* @var string
@@ -57,6 +52,25 @@ class BlockListBuilder extends ConfigEntityListBuilder implements FormInterface
protected $blockManager;
/**
+ * The theme manager.
+ *
+ * @var \Drupal\Core\Theme\ThemeManagerInterface
+ */
+ protected $themeManager;
+
+ /**
+ * The form builder.
+ *
+ * @var \Drupal\Core\Form\FormBuilderInterface
+ */
+ protected $formBuilder;
+
+ /**
+ * {@inheritdoc}
+ */
+ protected $limit = FALSE;
+
+ /**
* Constructs a new BlockListBuilder object.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
@@ -65,11 +79,17 @@ class BlockListBuilder extends ConfigEntityListBuilder implements FormInterface
* The entity storage class.
* @param \Drupal\Core\Block\BlockManagerInterface $block_manager
* The block manager.
+ * @param \Drupal\Core\Theme\ThemeManagerInterface $theme_manager
+ * The theme manager.
+ * @param \Drupal\Core\Form\FormBuilderInterface $form_builder
+ * The form builder.
*/
- public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, BlockManagerInterface $block_manager) {
+ public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, BlockManagerInterface $block_manager, ThemeManagerInterface $theme_manager, FormBuilderInterface $form_builder) {
parent::__construct($entity_type, $storage);
$this->blockManager = $block_manager;
+ $this->themeManager = $theme_manager;
+ $this->formBuilder = $form_builder;
}
/**
@@ -79,33 +99,14 @@ public static function createInstance(ContainerInterface $container, EntityTypeI
return new static(
$entity_type,
$container->get('entity.manager')->getStorage($entity_type->id()),
- $container->get('plugin.manager.block')
+ $container->get('plugin.manager.block'),
+ $container->get('theme.manager'),
+ $container->get('form_builder')
);
}
/**
* {@inheritdoc}
- */
- public function load() {
- // If no theme was specified, use the current theme.
- if (!$this->theme) {
- $this->theme = \Drupal::theme()->getActiveTheme()->getName();
- }
-
- // Store the region list.
- $this->regions = system_region_list($this->theme, REGIONS_VISIBLE);
-
- // Load only blocks for this theme, and sort them.
- // @todo Move the functionality of _block_rehash() out of the listing page.
- $entities = _block_rehash($this->theme);
-
- // Sort the blocks using \Drupal\block\Entity\Block::sort().
- uasort($entities, array($this->entityType->getClass(), 'sort'));
- return $entities;
- }
-
- /**
- * {@inheritdoc}
*
* @param string|null $theme
* (optional) The theme to display the blocks for. If NULL, the current
@@ -118,10 +119,9 @@ public function load() {
*/
public function render($theme = NULL, Request $request = NULL) {
$this->request = $request;
- // If no theme was specified, use the current theme.
- $this->theme = $theme ?: \Drupal::theme()->getActiveTheme()->getName();
+ $this->theme = $theme;
- return \Drupal::formBuilder()->getForm($this);
+ return $this->formBuilder->getForm($this);
}
/**
@@ -132,55 +132,42 @@ public function getFormId() {
}
/**
- * Implements \Drupal\Core\Form\FormInterface::buildForm().
- *
- * Form constructor for the main block administration form.
+ * {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
- $placement = FALSE;
- if ($this->request->query->has('block-placement')) {
- $placement = $this->request->query->get('block-placement');
- $form['#attached']['drupalSettings']['blockPlacement'] = $placement;
- }
- $entities = $this->load();
$form['#theme'] = array('block_list');
$form['#attached']['library'][] = 'core/drupal.tableheader';
$form['#attached']['library'][] = 'block/drupal.block';
$form['#attached']['library'][] = 'block/drupal.block.admin';
$form['#attributes']['class'][] = 'clearfix';
- // Add a last region for disabled blocks.
- $block_regions_with_disabled = $this->regions + array(BlockInterface::BLOCK_REGION_NONE => BlockInterface::BLOCK_REGION_NONE);
- $form['block_regions'] = array(
- '#type' => 'value',
- '#value' => $block_regions_with_disabled,
- );
-
- // Weights range from -delta to +delta, so delta should be at least half
- // of the amount of blocks present. This makes sure all blocks in the same
- // region get an unique weight.
- $weight_delta = round(count($entities) / 2);
-
// Build the form tree.
- $form['edited_theme'] = array(
- '#type' => 'value',
- '#value' => $this->theme,
+ $form['blocks'] = $this->buildBlocksForm();
+ $form['place_blocks'] = $this->buildPlaceBlocksForm();
+
+ $form['actions'] = array(
+ '#tree' => FALSE,
+ '#type' => 'actions',
);
- $form['blocks'] = array(
- '#type' => 'table',
- '#header' => array(
- t('Block'),
- t('Category'),
- t('Region'),
- t('Weight'),
- t('Operations'),
- ),
- '#attributes' => array(
- 'id' => 'blocks',
- ),
+ $form['actions']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => $this->t('Save blocks'),
+ '#button_type' => 'primary',
);
+ return $form;
+ }
+
+ /**
+ * Builds the main "Blocks" portion of the form.
+ *
+ * @return array
+ */
+ protected function buildBlocksForm() {
// Build blocks first for each region.
+ $blocks = [];
+ $entities = $this->load();
+ /** @var \Drupal\block\BlockInterface[] $entities */
foreach ($entities as $entity_id => $entity) {
$definition = $entity->getPlugin()->getPluginDefinition();
$blocks[$entity->getRegion()][$entity_id] = array(
@@ -189,39 +176,66 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'weight' => $entity->getWeight(),
'entity' => $entity,
'category' => $definition['category'],
+ 'status' => $entity->status(),
);
}
+ $form = array(
+ '#type' => 'table',
+ '#header' => array(
+ $this->t('Block'),
+ $this->t('Category'),
+ $this->t('Region'),
+ $this->t('Weight'),
+ $this->t('Operations'),
+ ),
+ '#attributes' => array(
+ 'id' => 'blocks',
+ ),
+ );
+
+ // Weights range from -delta to +delta, so delta should be at least half
+ // of the amount of blocks present. This makes sure all blocks in the same
+ // region get an unique weight.
+ $weight_delta = round(count($entities) / 2);
+
+ $placement = FALSE;
+ if ($this->request->query->has('block-placement')) {
+ $placement = $this->request->query->get('block-placement');
+ $form['#attached']['drupalSettings']['blockPlacement'] = $placement;
+ }
+
// Loop over each region and build blocks.
- foreach ($block_regions_with_disabled as $region => $title) {
- $form['blocks']['#tabledrag'][] = array(
+ $regions = $this->systemRegionList($this->getThemeName(), REGIONS_VISIBLE);
+ foreach ($regions as $region => $title) {
+ $form['#tabledrag'][] = array(
'action' => 'match',
'relationship' => 'sibling',
'group' => 'block-region-select',
'subgroup' => 'block-region-' . $region,
'hidden' => FALSE,
);
- $form['blocks']['#tabledrag'][] = array(
+ $form['#tabledrag'][] = array(
'action' => 'order',
'relationship' => 'sibling',
'group' => 'block-weight',
'subgroup' => 'block-weight-' . $region,
);
- $form['blocks'][$region] = array(
+ $form['region-' . $region] = array(
'#attributes' => array(
'class' => array('region-title', 'region-title-' . $region),
'no_striping' => TRUE,
),
);
- $form['blocks'][$region]['title'] = array(
- '#markup' => $region != BlockInterface::BLOCK_REGION_NONE ? $title : t('Disabled', array(), array('context' => 'Plural')),
+ $form['region-' . $region]['title'] = array(
+ '#markup' => $title,
'#wrapper_attributes' => array(
'colspan' => 5,
),
);
- $form['blocks'][$region . '-message'] = array(
+ $form['region-' . $region . '-message'] = array(
'#attributes' => array(
'class' => array(
'region-message',
@@ -230,8 +244,8 @@ public function buildForm(array $form, FormStateInterface $form_state) {
),
),
);
- $form['blocks'][$region . '-message']['message'] = array(
- '#markup' => '' . t('No blocks in this region') . '',
+ $form['region-' . $region . '-message']['message'] = array(
+ '#markup' => '' . $this->t('No blocks in this region') . '',
'#wrapper_attributes' => array(
'colspan' => 5,
),
@@ -241,74 +255,73 @@ public function buildForm(array $form, FormStateInterface $form_state) {
foreach ($blocks[$region] as $info) {
$entity_id = $info['entity_id'];
- $form['blocks'][$entity_id] = array(
+ $form[$entity_id] = array(
'#attributes' => array(
'class' => array('draggable'),
),
);
+ $form[$entity_id]['#attributes']['class'][] = $info['status'] ? 'block-enabled' : 'block-disabled';
if ($placement && $placement == Html::getClass($entity_id)) {
- $form['blocks'][$entity_id]['#attributes']['class'][] = 'color-warning';
- $form['blocks'][$entity_id]['#attributes']['class'][] = 'js-block-placed';
+ $form[$entity_id]['#attributes']['class'][] = 'color-warning';
+ $form[$entity_id]['#attributes']['class'][] = 'js-block-placed';
}
- $form['blocks'][$entity_id]['info'] = array(
- '#markup' => SafeMarkup::checkPlain($info['label']),
+ $form[$entity_id]['info'] = array(
+ '#markup' => $info['status'] ? SafeMarkup::checkPlain($info['label']) : SafeMarkup::format('@label (disabled)', ['@label' => $info['label']]),
'#wrapper_attributes' => array(
'class' => array('block'),
),
);
- $form['blocks'][$entity_id]['type'] = array(
+ $form[$entity_id]['type'] = array(
'#markup' => $info['category'],
);
- $form['blocks'][$entity_id]['region-theme']['region'] = array(
+ $form[$entity_id]['region-theme']['region'] = array(
'#type' => 'select',
'#default_value' => $region,
- '#empty_value' => BlockInterface::BLOCK_REGION_NONE,
- '#title' => t('Region for @block block', array('@block' => $info['label'])),
+ '#required' => TRUE,
+ '#title' => $this->t('Region for @block block', array('@block' => $info['label'])),
'#title_display' => 'invisible',
- '#options' => $this->regions,
+ '#options' => $regions,
'#attributes' => array(
'class' => array('block-region-select', 'block-region-' . $region),
),
'#parents' => array('blocks', $entity_id, 'region'),
);
- $form['blocks'][$entity_id]['region-theme']['theme'] = array(
+ $form[$entity_id]['region-theme']['theme'] = array(
'#type' => 'hidden',
- '#value' => $this->theme,
+ '#value' => $this->getThemeName(),
'#parents' => array('blocks', $entity_id, 'theme'),
);
- $form['blocks'][$entity_id]['weight'] = array(
+ $form[$entity_id]['weight'] = array(
'#type' => 'weight',
'#default_value' => $info['weight'],
'#delta' => $weight_delta,
- '#title' => t('Weight for @block block', array('@block' => $info['label'])),
+ '#title' => $this->t('Weight for @block block', array('@block' => $info['label'])),
'#title_display' => 'invisible',
'#attributes' => array(
'class' => array('block-weight', 'block-weight-' . $region),
),
);
- $form['blocks'][$entity_id]['operations'] = $this->buildOperations($info['entity']);
+ $form[$entity_id]['operations'] = $this->buildOperations($info['entity']);
}
}
}
// Do not allow disabling the main system content block when it is present.
- if (isset($form['blocks']['system_main']['region'])) {
- $form['blocks']['system_main']['region']['#required'] = TRUE;
+ if (isset($form['system_main']['region'])) {
+ $form['system_main']['region']['#required'] = TRUE;
}
+ return $form;
+ }
- $form['actions'] = array(
- '#tree' => FALSE,
- '#type' => 'actions',
- );
- $form['actions']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Save blocks'),
- '#button_type' => 'primary',
- );
-
- $form['place_blocks']['title'] = array(
+ /**
+ * Builds the "Place Blocks" portion of the form.
+ *
+ * @return array
+ */
+ protected function buildPlaceBlocksForm() {
+ $form['title'] = array(
'#type' => 'container',
- '#markup' => '' . t('Place blocks') . '
',
+ '#markup' => '' . $this->t('Place blocks') . '
',
'#attributes' => array(
'class' => array(
'entity-meta__header',
@@ -316,21 +329,21 @@ public function buildForm(array $form, FormStateInterface $form_state) {
),
);
- $form['place_blocks']['filter'] = array(
+ $form['filter'] = array(
'#type' => 'search',
- '#title' => t('Filter'),
+ '#title' => $this->t('Filter'),
'#title_display' => 'invisible',
'#size' => 30,
- '#placeholder' => t('Filter by block name'),
+ '#placeholder' => $this->t('Filter by block name'),
'#attributes' => array(
'class' => array('block-filter-text'),
'data-element' => '.entity-meta',
- 'title' => t('Enter a part of the block name to filter by.'),
+ 'title' => $this->t('Enter a part of the block name to filter by.'),
),
);
- $form['place_blocks']['list']['#type'] = 'container';
- $form['place_blocks']['list']['#attributes']['class'][] = 'entity-meta';
+ $form['list']['#type'] = 'container';
+ $form['list']['#attributes']['class'][] = 'entity-meta';
// Only add blocks which work without any available context.
$definitions = $this->blockManager->getDefinitionsForContexts();
@@ -338,8 +351,8 @@ public function buildForm(array $form, FormStateInterface $form_state) {
foreach ($sorted_definitions as $plugin_id => $plugin_definition) {
$category = SafeMarkup::checkPlain($plugin_definition['category']);
$category_key = 'category-' . $category;
- if (!isset($form['place_blocks']['list'][$category_key])) {
- $form['place_blocks']['list'][$category_key] = array(
+ if (!isset($form['list'][$category_key])) {
+ $form['list'][$category_key] = array(
'#type' => 'details',
'#title' => $category,
'#open' => TRUE,
@@ -354,7 +367,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
),
);
}
- $form['place_blocks']['list'][$category_key]['content']['#links'][$plugin_id] = array(
+ $form['list'][$category_key]['content']['#links'][$plugin_id] = array(
'title' => $plugin_definition['admin_label'],
'url' => Url::fromRoute('block.admin_add', [
'plugin_id' => $plugin_id,
@@ -373,42 +386,59 @@ public function buildForm(array $form, FormStateInterface $form_state) {
}
/**
+ * Gets the name of the theme used for this block listing.
+ *
+ * @return string
+ * The name of the theme.
+ */
+ protected function getThemeName() {
+ // If no theme was specified, use the current theme.
+ if (!$this->theme) {
+ $this->theme = $this->themeManager->getActiveTheme()->getName();
+ }
+ return $this->theme;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getEntityIds() {
+ return $this->getStorage()->getQuery()
+ ->condition('theme', $this->getThemeName())
+ ->sort($this->entityType->getKey('id'))
+ ->execute();
+ }
+
+ /**
* {@inheritdoc}
*/
public function getDefaultOperations(EntityInterface $entity) {
$operations = parent::getDefaultOperations($entity);
if (isset($operations['edit'])) {
- $operations['edit']['title'] = t('Configure');
+ $operations['edit']['title'] = $this->t('Configure');
}
return $operations;
}
/**
- * Implements \Drupal\Core\Form\FormInterface::validateForm().
+ * {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
// No validation.
}
/**
- * Implements \Drupal\Core\Form\FormInterface::submitForm().
- *
- * Form submission handler for the main block administration form.
+ * {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$entities = $this->storage->loadMultiple(array_keys($form_state->getValue('blocks')));
+ /** @var \Drupal\block\BlockInterface[] $entities */
foreach ($entities as $entity_id => $entity) {
$entity_values = $form_state->getValue(array('blocks', $entity_id));
$entity->setWeight($entity_values['weight']);
$entity->setRegion($entity_values['region']);
- if ($entity->getRegion() == BlockInterface::BLOCK_REGION_NONE) {
- $entity->disable();
- }
- else {
- $entity->enable();
- }
$entity->save();
}
drupal_set_message(t('The block settings have been updated.'));
@@ -417,4 +447,11 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$this->request->query->remove('block-placement');
}
+ /**
+ * Wraps system_region_list().
+ */
+ protected function systemRegionList($theme, $show = REGIONS_ALL) {
+ return system_region_list($theme, $show);
+ }
+
}
diff --git a/core/modules/block/src/Controller/BlockController.php b/core/modules/block/src/Controller/BlockController.php
index 66ecbbd..2265e2f 100644
--- a/core/modules/block/src/Controller/BlockController.php
+++ b/core/modules/block/src/Controller/BlockController.php
@@ -7,6 +7,7 @@
namespace Drupal\block\Controller;
+use Drupal\block\BlockInterface;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Extension\ThemeHandler;
use Drupal\Core\Extension\ThemeHandlerInterface;
@@ -45,6 +46,23 @@ public static function create(ContainerInterface $container) {
}
/**
+ * Calls a method on a block and reloads the listing page.
+ *
+ * @param \Drupal\block\BlockInterface $block
+ * The block being acted upon.
+ * @param string $op
+ * The operation to perform, e.g., 'enable' or 'disable'.
+ *
+ * @return \Symfony\Component\HttpFoundation\RedirectResponse
+ * A redirect back to the listing page.
+ */
+ public function performOperation(BlockInterface $block, $op) {
+ $block->$op()->save();
+ drupal_set_message($this->t('The block settings have been updated.'));
+ return $this->redirect('block.admin_display');
+ }
+
+ /**
* Returns a block theme demo page.
*
* @param string $theme
diff --git a/core/modules/block/src/Entity/Block.php b/core/modules/block/src/Entity/Block.php
index 948d293..f503779 100644
--- a/core/modules/block/src/Entity/Block.php
+++ b/core/modules/block/src/Entity/Block.php
@@ -33,11 +33,14 @@
* },
* admin_permission = "administer blocks",
* entity_keys = {
- * "id" = "id"
+ * "id" = "id",
+ * "status" = "status"
* },
* links = {
* "delete-form" = "/admin/structure/block/manage/{block}/delete",
- * "edit-form" = "/admin/structure/block/manage/{block}"
+ * "edit-form" = "/admin/structure/block/manage/{block}",
+ * "enable" = "/admin/structure/block/manage/{block}/enable",
+ * "disable" = "/admin/structure/block/manage/{block}/disable",
* },
* config_export = {
* "id",
@@ -75,7 +78,7 @@ class Block extends ConfigEntityBase implements BlockInterface, EntityWithPlugin
*
* @var string
*/
- protected $region = self::BLOCK_REGION_NONE;
+ protected $region;
/**
* The block weight.
@@ -214,13 +217,13 @@ public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b)
if ($status !== 0) {
return $status;
}
- // Sort by weight, unless disabled.
- if ($a->getRegion() != static::BLOCK_REGION_NONE) {
- $weight = $a->getWeight() - $b->getWeight();
- if ($weight) {
- return $weight;
- }
+
+ // Sort by weight.
+ $weight = $a->getWeight() - $b->getWeight();
+ if ($weight) {
+ return $weight;
}
+
// Sort by label.
return strcmp($a->label(), $b->label());
}
diff --git a/core/modules/block/src/Tests/BlockStorageUnitTest.php b/core/modules/block/src/Tests/BlockStorageUnitTest.php
index f1d435a..1c57c34 100644
--- a/core/modules/block/src/Tests/BlockStorageUnitTest.php
+++ b/core/modules/block/src/Tests/BlockStorageUnitTest.php
@@ -90,7 +90,7 @@ protected function createTests() {
'dependencies' => array('module' => array('block_test'), 'theme' => array('stark')),
'id' => 'test_block',
'theme' => 'stark',
- 'region' => '-1',
+ 'region' => NULL,
'weight' => NULL,
'provider' => NULL,
'plugin' => 'test_html',
@@ -120,7 +120,7 @@ protected function loadTests() {
$this->assertTrue($entity instanceof Block, 'The loaded entity is a Block.');
// Verify several properties of the block.
- $this->assertEqual($entity->getRegion(), '-1');
+ $this->assertEqual($entity->getRegion(), NULL);
$this->assertTrue($entity->status());
$this->assertEqual($entity->getTheme(), 'stark');
$this->assertTrue($entity->uuid());
diff --git a/core/modules/block/src/Tests/BlockTest.php b/core/modules/block/src/Tests/BlockTest.php
index 8c65bc3..8e4e5e4 100644
--- a/core/modules/block/src/Tests/BlockTest.php
+++ b/core/modules/block/src/Tests/BlockTest.php
@@ -155,10 +155,9 @@ function testBlock() {
$this->moveBlockToRegion($block, $region);
}
- // Set the block to the disabled region.
- $edit = array();
- $edit['blocks[' . $block['id'] . '][region]'] = -1;
- $this->drupalPostForm('admin/structure/block', $edit, t('Save blocks'));
+ // Disable the block.
+ $this->drupalGet('admin/structure/block');
+ $this->clickLink('Disable');
// Confirm that the block is now listed as disabled.
$this->assertText(t('The block settings have been updated.'), 'Block successfully move to disabled region.');
diff --git a/core/modules/block/src/Tests/BlockUiTest.php b/core/modules/block/src/Tests/BlockUiTest.php
index aba4ba1..8dfcc79 100644
--- a/core/modules/block/src/Tests/BlockUiTest.php
+++ b/core/modules/block/src/Tests/BlockUiTest.php
@@ -177,12 +177,15 @@ public function testMachineNameSuggestion() {
$url = 'admin/structure/block/add/test_block_instantiation/classy';
$this->drupalGet($url);
$this->assertFieldByName('id', 'displaymessage', 'Block form uses raw machine name suggestion when no instance already exists.');
- $this->drupalPostForm($url, array(), 'Save block');
+ $edit = ['region' => 'content'];
+ $this->drupalPostForm($url, $edit, 'Save block');
+ $this->assertText('The block configuration has been saved.');
// Now, check to make sure the form starts by autoincrementing correctly.
$this->drupalGet($url);
$this->assertFieldByName('id', 'displaymessage_2', 'Block form appends _2 to plugin-suggested machine name when an instance already exists.');
- $this->drupalPostForm($url, array(), 'Save block');
+ $this->drupalPostForm($url, $edit, 'Save block');
+ $this->assertText('The block configuration has been saved.');
// And verify that it continues working beyond just the first two.
$this->drupalGet($url);
diff --git a/core/modules/block/src/Tests/Views/DisplayBlockTest.php b/core/modules/block/src/Tests/Views/DisplayBlockTest.php
index 3f96ab1..297c6ae 100644
--- a/core/modules/block/src/Tests/Views/DisplayBlockTest.php
+++ b/core/modules/block/src/Tests/Views/DisplayBlockTest.php
@@ -191,8 +191,10 @@ public function testViewsBlockForm() {
// Test that that machine name field is hidden from display and has been
// saved as expected from the default value.
$this->assertNoFieldById('edit-machine-name', 'views_block__test_view_block_1', 'The machine name is hidden on the views block form.');
+
// Save the block.
- $this->drupalPostForm(NULL, array(), t('Save block'));
+ $edit = ['region' => 'content'];
+ $this->drupalPostForm(NULL, $edit, t('Save block'));
$storage = $this->container->get('entity.manager')->getStorage('block');
$block = $storage->load('views_block__test_view_block_block_1');
// This will only return a result if our new block has been created with the
@@ -201,7 +203,7 @@ public function testViewsBlockForm() {
for ($i = 2; $i <= 3; $i++) {
// Place the same block again and make sure we have a new ID.
- $this->drupalPostForm('admin/structure/block/add/views_block:test_view_block-block_1/' . $default_theme, array(), t('Save block'));
+ $this->drupalPostForm('admin/structure/block/add/views_block:test_view_block-block_1/' . $default_theme, $edit, t('Save block'));
$block = $storage->load('views_block__test_view_block_block_1_' . $i);
// This will only return a result if our new block has been created with the
// expected machine name.
@@ -210,7 +212,7 @@ public function testViewsBlockForm() {
// Tests the override capability of items per page.
$this->drupalGet('admin/structure/block/add/views_block:test_view_block-block_1/' . $default_theme);
- $edit = array();
+ $edit = ['region' => 'content'];
$edit['settings[override][items_per_page]'] = 10;
$this->drupalPostForm('admin/structure/block/add/views_block:test_view_block-block_1/' . $default_theme, $edit, t('Save block'));
@@ -228,7 +230,7 @@ public function testViewsBlockForm() {
$this->assertEqual(5, $config['items_per_page'], "'Items per page' is properly saved.");
// Tests the override of the label capability.
- $edit = array();
+ $edit = ['region' => 'content'];
$edit['settings[views_label_checkbox]'] = 1;
$edit['settings[views_label]'] = 'Custom title';
$this->drupalPostForm('admin/structure/block/add/views_block:test_view_block-block_1/' . $default_theme, $edit, t('Save block'));
diff --git a/core/modules/block_content/src/Tests/BlockContentCreationTest.php b/core/modules/block_content/src/Tests/BlockContentCreationTest.php
index 6bf250c..bda0bea 100644
--- a/core/modules/block_content/src/Tests/BlockContentCreationTest.php
+++ b/core/modules/block_content/src/Tests/BlockContentCreationTest.php
@@ -104,6 +104,7 @@ public function testBlockContentCreationMultipleViewModes() {
$this->assertFieldByXPath('//select[@name="settings[view_mode]"]', NULL, 'View mode setting shown because multiple exist');
// Change the view mode.
+ $view_mode['region'] = 'content';
$view_mode['settings[view_mode]'] = 'test_view_mode';
$this->drupalPostForm(NULL, $view_mode, t('Save block'));
diff --git a/core/modules/block_content/src/Tests/BlockContentTypeTest.php b/core/modules/block_content/src/Tests/BlockContentTypeTest.php
index 4270538..0312798 100644
--- a/core/modules/block_content/src/Tests/BlockContentTypeTest.php
+++ b/core/modules/block_content/src/Tests/BlockContentTypeTest.php
@@ -206,7 +206,7 @@ public function testsBlockContentAddTypes() {
if (!empty($blocks)) {
$block = reset($blocks);
$this->assertUrl(\Drupal::url('block.admin_add', array('plugin_id' => 'block_content:' . $block->uuid(), 'theme' => $theme), array('absolute' => TRUE)));
- $this->drupalPostForm(NULL, array(), t('Save block'));
+ $this->drupalPostForm(NULL, ['region' => 'content'], t('Save block'));
$this->assertUrl(\Drupal::url('block.admin_display_theme', array('theme' => $theme), array('absolute' => TRUE, 'query' => array('block-placement' => Html::getClass($edit['info[0][value]'])))));
}
else {
diff --git a/core/modules/system/src/Tests/System/AccessDeniedTest.php b/core/modules/system/src/Tests/System/AccessDeniedTest.php
index 0f37320..810cd87 100644
--- a/core/modules/system/src/Tests/System/AccessDeniedTest.php
+++ b/core/modules/system/src/Tests/System/AccessDeniedTest.php
@@ -58,7 +58,7 @@ function testAccessDenied() {
$this->drupalPostForm('admin/config/system/site-information', $edit, t('Save configuration'));
// Enable the user login block.
- $this->drupalPlaceBlock('user_login_block', array('id' => 'login'));
+ $block = $this->drupalPlaceBlock('user_login_block', array('id' => 'login'));
// Log out and check that the user login block is shown on custom 403 pages.
$this->drupalLogout();
@@ -83,10 +83,7 @@ function testAccessDenied() {
// Log back in, set the custom 403 page to /user/login and remove the block
$this->drupalLogin($this->adminUser);
$this->config('system.site')->set('page.403', '/user/login')->save();
- $edit = [
- 'region' => -1,
- ];
- $this->drupalPostForm('admin/structure/block/manage/login', $edit, t('Save block'));
+ $block->disable()->save();
// Check that we can log in from the 403 page.
$this->drupalLogout();