diff --git a/core/modules/aggregator/aggregator.module b/core/modules/aggregator/aggregator.module
index 35cdc19..2fd5929 100644
--- a/core/modules/aggregator/aggregator.module
+++ b/core/modules/aggregator/aggregator.module
@@ -371,11 +371,9 @@ function aggregator_save_category($edit) {
->condition('cid', $edit['cid'])
->execute();
// Make sure there is no active block for this category.
- $block_configs = config_get_storage_names_with_prefix('plugin.core.block');
- foreach ($block_configs as $config_id) {
- $config = config($config_id);
- if ($config->get('id') == 'aggregator_category_block:' . $edit['cid']) {
- $config->delete();
+ if (module_exists('block')) {
+ foreach (entity_load_multiple_by_properties('block', array('plugin' => 'aggregator_category_block:' . $edit['cid'])) as $block) {
+ $block->delete();
}
}
$edit['title'] = '';
@@ -439,11 +437,9 @@ function aggregator_save_feed($edit) {
->condition('fid', $edit['fid'])
->execute();
// Make sure there is no active block for this feed.
- $block_configs = config_get_storage_names_with_prefix('plugin.core.block');
- foreach ($block_configs as $config_id) {
- $config = config($config_id);
- if ($config->get('id') == 'aggregator_feed_block:' . $edit['fid']) {
- $config->delete();
+ if (module_exists('block')) {
+ foreach (entity_load_multiple_by_properties('block', array('plugin' => 'aggregator_feed_block:' . $edit['fid'])) as $block) {
+ $block->delete();
}
}
}
diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/block/block/AggregatorCategoryBlock.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/block/block/AggregatorCategoryBlock.php
index 4c2df27..d281731 100644
--- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/block/block/AggregatorCategoryBlock.php
+++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/block/block/AggregatorCategoryBlock.php
@@ -10,6 +10,7 @@
use Drupal\block\BlockBase;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
+use Drupal\block\Plugin\Core\Entity\Block;
/**
* Provides an 'Aggregator category' block for the latest items in a category.
@@ -64,7 +65,7 @@ public function blockSubmit($form, &$form_state) {
/**
* Implements \Drupal\block\BlockBase::blockBuild().
*/
- public function blockBuild() {
+ public function blockBuild(Block $entity) {
$id = $this->getPluginId();
if ($category = db_query('SELECT cid, title, block FROM {aggregator_category} WHERE cid = :cid', array(':cid' => $id))->fetchObject()) {
$result = db_query_range('SELECT i.* FROM {aggregator_category_item} ci LEFT JOIN {aggregator_item} i ON ci.iid = i.iid WHERE ci.cid = :cid ORDER BY i.timestamp DESC, i.iid DESC', 0, $this->configuration['block_count'], array(':cid' => $category->cid));
diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/block/block/AggregatorFeedBlock.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/block/block/AggregatorFeedBlock.php
index e902eb5..528c7db 100644
--- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/block/block/AggregatorFeedBlock.php
+++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/block/block/AggregatorFeedBlock.php
@@ -10,6 +10,7 @@
use Drupal\block\BlockBase;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
+use Drupal\block\Plugin\Core\Entity\Block;
/**
* Provides an 'Aggregator feed' block with the latest items from the feed.
@@ -64,7 +65,7 @@ public function blockSubmit($form, &$form_state) {
/**
* Implements \Drupal\block\BlockBase::blockBuild().
*/
- public function blockBuild() {
+ public function blockBuild(Block $entity) {
// Plugin IDs look something like this: aggregator_feed_block:1.
list(, $id) = explode(':', $this->getPluginId());
if ($feed = db_query('SELECT fid, title, block FROM {aggregator_feed} WHERE block <> 0 AND fid = :fid', array(':fid' => $id))->fetchObject()) {
diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorRenderingTest.php b/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorRenderingTest.php
index 1f13232..e1f8fcd 100644
--- a/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorRenderingTest.php
+++ b/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorRenderingTest.php
@@ -39,8 +39,7 @@ public function testBlockLinks() {
$this->updateFeedItems($feed, $this->getDefaultFeedItemCount());
// Clear the block cache to load the new block definitions.
- $manager = $this->container->get('plugin.manager.block');
- $manager->clearCachedDefinitions();
+ $this->container->get('plugin.manager.block')->clearCachedDefinitions();
// Need admin user to be able to access block admin.
$admin_user = $this->drupalCreateUser(array(
@@ -51,15 +50,11 @@ public function testBlockLinks() {
));
$this->drupalLogin($admin_user);
- $block = array(
- 'title' => 'feed-' . $feed->title,
- 'block_count' => 2,
- );
- $this->drupalPlaceBlock("aggregator_feed_block:{$feed->fid}", $block);
+ $block = $this->drupalPlaceBlock("aggregator_feed_block:{$feed->fid}", array('label' => 'feed-' . $feed->title), array('block_count' => 2));
// Confirm that the block is now being displayed on pages.
$this->drupalGet('node');
- $this->assertText(t($block['title']), 'Feed block is displayed on the page.');
+ $this->assertText($block->label(), 'Feed block is displayed on the page.');
// Find the expected read_more link.
$href = 'aggregator/sources/' . $feed->fid;
@@ -77,7 +72,7 @@ public function testBlockLinks() {
aggregator_save_feed((array) $feed);
// Check that the block is no longer displayed.
$this->drupalGet('node');
- $this->assertNoText(t($block['title']), 'Feed block is not displayed on the page when number of items is set to 0.');
+ $this->assertNoText($block->label(), 'Feed block is not displayed on the page when number of items is set to 0.');
}
/**
diff --git a/core/modules/block/block.admin.inc b/core/modules/block/block.admin.inc
index 13f17ad..c3955fc 100644
--- a/core/modules/block/block.admin.inc
+++ b/core/modules/block/block.admin.inc
@@ -5,6 +5,8 @@
* Admin page callbacks for the block module.
*/
+use Drupal\block\Plugin\Core\Entity\Block;
+
/**
* Page callback: Attaches CSS for the block region demo.
*
@@ -18,310 +20,80 @@ function block_admin_demo($theme = NULL) {
/**
* Page callback: Shows the block administration page.
*
- * @param $theme
- * The theme to display the administration page for. If not provided, defaults
- * to the currently used theme.
- *
- * @see block_menu()
- */
-function block_admin_display($theme = NULL) {
- global $theme_key;
-
- drupal_theme_initialize();
-
- if (!isset($theme)) {
- // If theme is not specifically set, rehash for the current theme.
- $theme = $theme_key;
- }
-
- // Fetch and sort blocks.
- $blocks = block_admin_display_prepare_blocks($theme);
-
- return drupal_get_form('block_admin_display_form', $blocks, $theme);
-}
-
-/**
- * Prepares a list of blocks for display on the blocks administration page.
- *
- * @param $theme
- * The machine-readable name of the theme whose blocks should be returned.
- *
- * @return
- * An array of blocks, as returned by _block_rehash(), sorted by region in
- * preparation for display on the blocks administration page.
- *
- * @see block_admin_display_form()
- */
-function block_admin_display_prepare_blocks($theme) {
- $blocks = _block_rehash($theme);
- $compare_theme = &drupal_static('_block_compare:theme');
- $compare_theme = $theme;
- usort($blocks, '_block_compare');
- return $blocks;
-}
-
-/**
- * Form constructor for the main block administration form.
- *
- * @param $blocks
- * An array of blocks, as returned by block_admin_display_prepare_blocks().
- * @param $theme
- * A string representing the name of the theme to edit blocks for.
- * @param $block_regions
- * (optional) An array of regions in which the blocks will be allowed to be
- * placed. Defaults to all visible regions for the theme whose blocks are
- * being configured. In all cases, a dummy region for disabled blocks will
- * also be displayed.
- *
- * @return
- * An array representing the form definition.
- *
- * @ingroup forms
- * @see block_admin_display_form_submit()
- */
-function block_admin_display_form($form, &$form_state, $blocks, $theme, $block_regions = NULL) {
- $path = drupal_get_path('module', 'block');
- $form['#attached']['css'][] = $path . '/block.admin.css';
- $form['#attached']['library'][] = array('system', 'drupal.tableheader');
- $form['#attached']['library'][] = array('block', 'drupal.block');
-
- // Get a list of block regions if one was not provided.
- if (!isset($block_regions)) {
- $block_regions = system_region_list($theme, REGIONS_VISIBLE);
- }
- // Add a last region for disabled blocks.
- $block_regions_with_disabled = $block_regions + array(BLOCK_REGION_NONE => BLOCK_REGION_NONE);
-
- foreach ($block_regions_with_disabled as $region => $title) {
- $form['#attached']['drupal_add_tabledrag'][] = array('blocks', 'match', 'sibling', 'block-region-select', 'block-region-' . $region, NULL, FALSE);
- $form['#attached']['drupal_add_tabledrag'][] = array('blocks', 'order', 'sibling', 'block-weight', 'block-weight-' . $region);
- }
-
- // 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($blocks) / 2);
-
- // Build the form tree.
- $form['edited_theme'] = array(
- '#type' => 'value',
- '#value' => $theme,
- );
- $form['block_regions'] = array(
- '#type' => 'value',
- '#value' => $block_regions_with_disabled,
- );
- $form['blocks'] = array();
- $form['#tree'] = TRUE;
-
- foreach ($blocks as $key => $instance) {
- $block = $instance->getConfig();
- $form['blocks'][$key]['config_id'] = array(
- '#type' => 'value',
- '#value' => $block['config_id'],
- );
- $info = $instance->getDefinition();
- $form['blocks'][$key]['info'] = array(
- '#markup' => check_plain($info['subject']),
- );
- $form['blocks'][$key]['theme'] = array(
- '#type' => 'hidden',
- '#value' => $theme,
- );
- $form['blocks'][$key]['weight'] = array(
- '#type' => 'weight',
- '#default_value' => $block['weight'],
- '#delta' => $weight_delta,
- '#title_display' => 'invisible',
- '#title' => t('Weight for @block block', array('@block' => $info['subject'])),
- );
- $form['blocks'][$key]['region'] = array(
- '#type' => 'select',
- '#default_value' => $block['region'] != BLOCK_REGION_NONE ? $block['region'] : NULL,
- '#empty_value' => BLOCK_REGION_NONE,
- '#title_display' => 'invisible',
- '#title' => t('Region for @block block', array('@block' => $info['subject'])),
- '#options' => $block_regions,
- );
- $links['configure'] = array(
- 'title' => t('configure'),
- 'href' => 'admin/structure/block/manage/' . $block['config_id'] . '/' . $theme . '/configure',
- );
- $links['delete'] = array(
- 'title' => t('delete'),
- 'href' => 'admin/structure/block/manage/' . $block['config_id'] . '/' . $theme . '/delete',
- );
- $form['blocks'][$key]['operations'] = array(
- '#type' => 'operations',
- '#links' => $links,
- );
- }
- // 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;
- }
-
- $form['actions'] = array(
- '#tree' => FALSE,
- '#type' => 'actions',
- );
- $form['actions']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Save blocks'),
- '#button_type' => 'primary',
- );
-
- return $form;
-}
-
-/**
- * Form submission handler for block_admin_display_form().
+ * @param string $theme
+ * The theme to display the administration page for.
*
- * @see block_admin_display_form()
- */
-function block_admin_display_form_submit($form, &$form_state) {
- foreach ($form_state['values']['blocks'] as $block) {
- $config = config($block['config_id']);
- $config->set('weight', $block['weight']);
- $config->set('region', $block['region']);
- $config->save();
- }
- drupal_set_message(t('The block settings have been updated.'));
- cache_invalidate_tags(array('content' => TRUE));
-}
-
-/**
- * Sorts active blocks by region, then by weight; sorts inactive blocks by name.
+ * @return array
+ * A render array for a page containing a list of blocks.
*
- * Callback for usort() in block_admin_display_prepare_blocks().
+ * @see block_menu()
*/
-function _block_compare($ainstance, $binstance) {
- global $theme_key;
- $a = $ainstance->getConfig();
- $b = $binstance->getConfig();
-
- // Theme should be set before calling this function, or the current theme
- // is being used.
- $theme = &drupal_static(__FUNCTION__ . ':theme');
- if (!isset($theme)) {
- $theme = $theme_key;
- }
-
- $regions = &drupal_static(__FUNCTION__ . ':regions');
- // We need the region list to correctly order by region.
- if (!isset($regions)) {
- $regions = array_flip(array_keys(system_region_list($theme)));
- $regions[BLOCK_REGION_NONE] = count($regions);
- }
-
- // Separate enabled from disabled.
- $status = $b['status'] - $a['status'];
- if ($status) {
- return $status;
- }
- // Sort by region (in the order defined by theme .info file).
- if ((!empty($a['region']) && !empty($b['region'])) && ($place = ($regions[$a['region']] - $regions[$b['region']]))) {
- return $place;
- }
- // Sort by weight, unless disabled.
- if ($a['region'] != BLOCK_REGION_NONE) {
- $weight = $a['weight'] - $b['weight'];
- if ($weight) {
- return $weight;
- }
- }
- // Sort by title.
- $ainfo = $ainstance->getDefinition();
- $binfo = $binstance->getDefinition();
- return strcmp($ainfo['subject'], $binfo['subject']);
+function block_admin_display($theme) {
+ return entity_list_controller('block')->render($theme);
}
/**
- * Form constructor for the block instance configuration form.
+ * Page callback: Build the block instance add form.
*
* @param string $plugin_id
* The plugin ID for the block instance.
* @param string $theme
- * (optional) The name of the theme for the block instance. If no theme is
- * specified, the default theme will be used.
- *
- * @see block_menu()
- * @see custom_block_menu()
- * @see block_admin_configure_validate()
- * @see block_admin_configure_submit()
+ * The name of the theme for the block instance.
*
- * @ingroup forms
+ * @return array
+ * The block instance edit form.
*/
-function block_admin_configure($form, &$form_state, $plugin_id, $theme = NULL) {
- $instance = block_load($plugin_id);
- $form['#instance'] = $instance;
- $config = $instance->getConfig();
- if (!isset($config['config_id']) && !$theme) {
- $theme = variable_get('theme_default', 'stark');
- }
- elseif (!$theme && isset($config['config_id'])) {
- list(, , , $theme) = explode('.', $config['config_id']);
- }
- $form['theme'] = array(
- '#type' => 'value',
- '#value' => $theme,
- );
- $form += $instance->form($form, $form_state);
- return $form;
+function block_admin_add($plugin_id, $theme) {
+ $entity = entity_create('block', array(
+ 'plugin' => $plugin_id,
+ 'theme' => $theme,
+ ));
+ return entity_get_form($entity);
}
/**
- * Form validation handler for block_admin_configure().
+ * Page callback: Build the block instance edit form.
*
- * @see block_admin_configure()
- * @see block_admin_configure_submit()
- */
-function block_admin_configure_validate($form, &$form_state) {
- $form['#instance']->validate($form, $form_state);
-}
-
-/**
- * Form submission handler for block_admin_configure().
+ * @param \Drupal\block\Plugin\Core\Entity\Block $entity
+ * The block instance.
*
- * @see block_admin_configure()
- * @see block_admin_configure_validate()
+ * @return array
+ * The block instance edit form.
*/
-function block_admin_configure_submit($form, &$form_state) {
- $form['#instance']->submit($form, $form_state);
- $config_values = $form['#instance']->getConfig();
- $machine_name = 'plugin.core.block.' . $form_state['values']['theme'] . '.' . $form_state['values']['machine_name'];
- $config = config($machine_name);
- $config->set('id', $form['#instance']->getPluginId());
- foreach ($config_values as $key => $value) {
- $config->set($key, $value);
+function block_admin_edit(Block $entity) {
+ // Get the theme for the page title.
+ $admin_theme = config('system.theme')->get('admin');
+ $themes = list_themes();
+ $theme_key = $entity->get('theme');
+ $theme = $themes[$theme_key];
+ // Use meaningful titles for the main site and administrative themes.
+ $theme_title = $theme->info['name'];
+ if ($theme_key == variable_get('theme_default', 'stark')) {
+ $theme_title = t('!theme (default theme)', array('!theme' => $theme_title));
+ }
+ elseif ($admin_theme && $theme_key == $admin_theme) {
+ $theme_title = t('!theme (administration theme)', array('!theme' => $theme_title));
}
- $config->save();
- drupal_set_message(t('The block configuration has been saved.'));
- cache_invalidate_tags(array('content' => TRUE));
- $form_state['redirect'] = 'admin/structure/block/list/block_plugin_ui:' . $form_state['values']['theme'];
+
+ // Get the block subject for the page title.
+ drupal_set_title(t("%label block in %theme", array('%label' => $entity->label(), '%theme' => $theme_title)), PASS_THROUGH);
+
+ return entity_get_form($entity);
}
/**
* Form constructor for the block instance deletion form.
*
- * @param string $plugin_id
- * The plugin ID for the block instance.
- * @param string $theme
- * The name of the theme for the block instance.
+ * @param \Drupal\block\Plugin\Core\Entity\Block $entity
+ * The block instance.
*
* @see block_menu()
* @see block_admin_block_delete_submit()
*/
-function block_admin_block_delete($form, &$form_state, $plugin_id, $theme) {
- $block = block_load($plugin_id);
- $form['id'] = array('#type' => 'value', '#value' => $plugin_id);
- $form['theme'] = array('#type' => 'value', '#value' => $theme);
- $definition = $block->getDefinition();
- $config = $block->getConfig();
- $subject = empty($config['subject']) ? $definition['subject'] : $config['subject'];
- $form['subject'] = array('#type' => 'value', '#value' => $subject);
+function block_admin_block_delete(array $form, array &$form_state, Block $entity) {
+ $form['id'] = array('#type' => 'value', '#value' => $entity->id());
- return confirm_form($form, t('Are you sure you want to delete the block %name?', array('%name' => $subject)), 'admin/structure/block', '', t('Delete'), t('Cancel'));
+ return confirm_form($form, t('Are you sure you want to delete the block %name?', array('%name' => $entity->label())), 'admin/structure/block', '', t('Delete'), t('Cancel'));
}
/**
@@ -330,10 +102,10 @@ function block_admin_block_delete($form, &$form_state, $plugin_id, $theme) {
* @see block_admin_block_delete()
*/
function block_admin_block_delete_submit($form, &$form_state) {
- $config = config($form_state['values']['id']);
- $config->delete();
- drupal_set_message(t('The block %name has been removed.', array('%name' => $form_state['values']['subject'])));
- $form_state['redirect'] = 'admin/structure/block/list/block_plugin_ui:' . $form_state['values']['theme'];
+ $entity = entity_load('block', $form_state['values']['id']);
+ drupal_set_message(t('The block %name has been removed.', array('%name' => $entity->label())));
+ $form_state['redirect'] = 'admin/structure/block/list/block_plugin_ui:' . $entity->get('theme');
+ $entity->delete();
}
/**
diff --git a/core/modules/block/block.api.php b/core/modules/block/block.api.php
index defde15..c889e68 100644
--- a/core/modules/block/block.api.php
+++ b/core/modules/block/block.api.php
@@ -29,7 +29,7 @@
* @see hook_block_view_ID_alter()
* @see hook_block_view_NAME_alter()
*/
-function hook_block_view_alter(array &$build, \Drupal\block\BlockInterface $block) {
+function hook_block_view_alter(array &$build, \Drupal\block\Plugin\Core\Entity\Block $block) {
// Remove the contextual links on all blocks that provide them.
if (is_array($build) && isset($build['#contextual_links'])) {
unset($build['#contextual_links']);
diff --git a/core/modules/block/block.module b/core/modules/block/block.module
index d9155c3..b6a5381 100644
--- a/core/modules/block/block.module
+++ b/core/modules/block/block.module
@@ -121,22 +121,29 @@ function block_menu() {
'access arguments' => array('administer blocks'),
'file' => 'block.admin.inc',
);
- $items['admin/structure/block/manage/%/%'] = array(
+ $items['admin/structure/block/add/%/%'] = array(
'title' => 'Configure block',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('block_admin_configure', 4, 5),
+ 'page callback' => 'block_admin_add',
+ 'page arguments' => array(4, 5),
+ 'access arguments' => array('administer blocks'),
+ 'file' => 'block.admin.inc',
+ );
+ $items['admin/structure/block/manage/%block'] = array(
+ 'title' => 'Configure block',
+ 'page callback' => 'block_admin_edit',
+ 'page arguments' => array(4),
'access arguments' => array('administer blocks'),
'file' => 'block.admin.inc',
);
- $items['admin/structure/block/manage/%/%/configure'] = array(
+ $items['admin/structure/block/manage/%block/configure'] = array(
'title' => 'Configure block',
'type' => MENU_DEFAULT_LOCAL_TASK,
'context' => MENU_CONTEXT_INLINE,
);
- $items['admin/structure/block/manage/%/%/delete'] = array(
+ $items['admin/structure/block/manage/%block/delete'] = array(
'title' => 'Delete block',
'page callback' => 'drupal_get_form',
- 'page arguments' => array('block_admin_block_delete', 4, 5),
+ 'page arguments' => array('block_admin_block_delete', 4),
'access arguments' => array('administer blocks'),
'type' => MENU_LOCAL_TASK,
'context' => MENU_CONTEXT_NONE,
@@ -306,27 +313,24 @@ function _block_get_renderable_region($list = array()) {
!in_array($_SERVER['REQUEST_METHOD'], array('GET', 'HEAD'));
foreach ($list as $key => $block) {
- $config = $block->getConfig();
- $definition = $block->getDefinition();
- $build[$key] = array(
- '#block' => $block,
- '#weight' => (int) $config['weight'],
- '#theme_wrappers' => array('block'),
- );
-
- if ($not_cacheable || in_array($config['cache'], array(DRUPAL_NO_CACHE, DRUPAL_CACHE_CUSTOM))) {
- // Non-cached blocks get built immediately. Provides more content
- // that can be easily manipulated during hook_page_alter().
- $build[$key] = _block_get_renderable_block($build[$key]);
+ $settings = $block->get('settings');
+ if ($not_cacheable || in_array($settings['cache'], array(DRUPAL_NO_CACHE, DRUPAL_CACHE_CUSTOM))) {
+ // Non-cached blocks get built immediately.
+ if ($block->access()) {
+ $build[$key] = entity_view($block, 'block');
+ }
}
else {
$key_components = explode('.', $key);
$id = array_pop($key_components);
- $build[$key] += array(
+ $build[$key] = array(
+ '#block' => $block,
+ '#weight' => $block->get('weight'),
+ '#theme_wrappers' => array('block'),
'#pre_render' => array('_block_get_renderable_block'),
'#cache' => array(
- 'keys' => array($id, $config['module']),
- 'granularity' => $config['cache'],
+ 'keys' => array($id, $block->get('module')),
+ 'granularity' => $settings['cache'],
'bin' => 'block',
'tags' => array('content' => TRUE),
),
@@ -338,9 +342,8 @@ function _block_get_renderable_region($list = array()) {
// skip the help block, since we assume that most users do not need or want
// to perform contextual actions on the help block, and the links needlessly
// draw attention on it.
- if ($definition['class'] != 'Drupal\\system\\Plugin\\block\\block\\SystemHelpBlock' && $definition['class'] != 'Drupal\\system\\Plugin\\block\\block\\SystemMainBlock') {
- global $theme;
- $build[$key]['#contextual_links']['block'] = array('admin/structure/block/manage', array($key, $theme));
+ if (!in_array($block->get('plugin'), array('system_help_block', 'system_main_block'))) {
+ $build[$key]['#contextual_links']['block'] = array('admin/structure/block/manage', array($key));
}
}
return $build;
@@ -357,33 +360,25 @@ function _block_get_renderable_region($list = array()) {
* Blocks currently exported by modules.
*/
function _block_rehash($theme = NULL) {
- $blocks = array();
- $instances = array();
$theme = $theme ? $theme : variable_get('theme_default', 'stark');
- $block_configs = config_get_storage_names_with_prefix('plugin.core.block.' . $theme);
$regions = system_region_list($theme);
- foreach ($block_configs as $config) {
- // Only list valid block instances.
- if (!$block = block_load($config)) {
- continue;
- }
- $blocks[$config] = $block;
- $config = config($config);
- $region = $config->get('region');
- $status = $config->get('status');
+ $blocks = entity_load_multiple_by_properties('block', array('theme' => $theme));
+ foreach ($blocks as $block_id => $block) {
+ $region = $block->get('region');
+ $status = $block->get('status');
// Disable blocks in invalid regions.
if (!empty($region) && $region != BLOCK_REGION_NONE && !isset($regions[$region]) && $status == 1) {
- drupal_set_message(t('The block %info was assigned to the invalid region %region and has been disabled.', array('%info' => $config->get('id'), '%region' => $region)), 'warning');
+ 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 modules are moved into the BLOCK_REGION_NONE later so no
// need to move the block to another region.
- $config->set('status', 0);
- $config->save();
+ $block->set('status', 0);
+ $block->save();
}
// Set region to none if not enabled and make sure status is set.
if (empty($status)) {
- $config->set('region', BLOCK_REGION_NONE);
- $config->set('status', 0);
- $config->save();
+ $block->set('region', BLOCK_REGION_NONE);
+ $block->set('status', 0);
+ $block->save();
}
}
return $blocks;
@@ -414,28 +409,22 @@ function block_themes_enabled($theme_list) {
*/
function block_theme_initialize($theme) {
// Initialize theme's blocks if none already registered.
- $has_blocks = config_get_storage_names_with_prefix('plugin.core.block.' . $theme);
+ $has_blocks = entity_load_multiple_by_properties('block', array('theme' => $theme));
if (!$has_blocks) {
$default_theme = variable_get('theme_default', 'stark');
// Apply only to new theme's visible regions.
$regions = system_region_list($theme, REGIONS_VISIBLE);
- $default_theme_blocks = config_get_storage_names_with_prefix('plugin.core.block.' . $default_theme);
- foreach ($default_theme_blocks as $config_id) {
- $block_config = config($config_id)->get();
- $machine_name = explode('.', $config_id);
- $machine_name = array_pop($machine_name);
- $new_config_id = 'plugin.core.block.' . $theme . '.' . $machine_name;
- $new_block = config($new_config_id);
+ $default_theme_blocks = entity_load_multiple_by_properties('block', array('theme' => $default_theme));
+ foreach ($default_theme_blocks as $default_theme_block_id => $default_theme_block) {
+ list(, $machine_name) = explode('.', $default_theme_block_id);
+ $block = $default_theme_block->createDuplicate();
+ $block->set('id', $theme . '.' . $machine_name);
// If the region isn't supported by the theme, assign the block to the
// theme's default region.
- if (!isset($regions[$block_config['region']])) {
- $new_block->set('region', system_default_region($theme));
- unset($block_config['region']);
- }
- foreach ($block_config as $key => $value) {
- $new_block->set($key, $value);
+ if (!isset($regions[$block->get('region')])) {
+ $block->set('region', system_default_region($theme));
}
- $new_block->save();
+ $block->save();
}
}
}
@@ -456,7 +445,11 @@ function block_list($region) {
$blocks = &drupal_static(__FUNCTION__);
if (!isset($blocks)) {
- $blocks = _block_load_blocks();
+ global $theme;
+ $blocks = array();
+ foreach (entity_load_multiple_by_properties('block', array('theme' => $theme)) as $block_id => $block) {
+ $blocks[$block->get('region')][$block_id] = $block;
+ }
}
// Create an empty array if there are no entries.
@@ -470,57 +463,16 @@ function block_list($region) {
/**
* Loads a block instance.
*
- * @param string $plugin_id
- * The plugin ID to load.
- * @param array $conf
- * An optional configuration array for creating a block instance manually
- * rather than retrieving it from the configuration system.
+ * This should only be used when entity_load() cannot be used directly.
*
- * @return
- * A block object.
+ * @param string $entity_id
+ * The block ID.
*
- * @todo Add block_load_multiple() and make this function a single-value wrapper.
+ * @return \Drupal\block\Plugin\Core\Entity\Block
+ * The loaded block object.
*/
-function block_load($plugin_id, array $conf = array()) {
- $manager = drupal_container()->get('plugin.manager.block');
- if (!$block = $manager->getInstance(array('config' => $plugin_id))) {
- // If the block instance does not exist, try to create it.
- try {
- $block = $manager->createInstance($plugin_id, $conf);
- }
- catch (PluginException $e) {
- $config = config($plugin_id)->get();
- // Ignore blocks belonging to disabled modules, but re-throw valid
- // exceptions when the module is enabled and the plugin is misconfigured.
- if (empty($config['module']) || module_exists($config['module'])) {
- throw $e;
- }
- return FALSE;
- }
- }
- return $block;
-}
-
-/**
- * Loads blocks' information from the configuration management system.
- *
- * @return
- * An array of blocks grouped by region.
- *
- * @todo Remove this function, and replace it with a block_load_multiple().
- */
-function _block_load_blocks() {
- global $theme;
- $blocks = array();
- $instances = config_get_storage_names_with_prefix('plugin.core.block.' . $theme);
- $manager = drupal_container()->get('plugin.manager.block');
- foreach ($instances as $plugin_id) {
- if ($block = block_load($plugin_id)) {
- $config = $block->getConfig();
- $blocks[$config['region']]["$plugin_id"] = $block;
- }
- }
- return $blocks;
+function block_load($entity_id) {
+ return entity_load('block', $entity_id);
}
/**
@@ -538,17 +490,7 @@ function _block_get_renderable_block($element) {
$block = $element['#block'];
// Don't bother to build blocks that aren't accessible.
if ($element['#access'] = $block->access()) {
- $build = $block->build();
- if ($build) {
- if (isset($build['#title'])) {
- $element['#title'] = $build['#title'];
- }
- $element += $build;
- }
- else {
- // @todo Add an inline comment explaining why this line is necessary.
- $element = array();
- }
+ $element += entity_view($block, 'block');
}
return $element;
}
@@ -590,10 +532,9 @@ function block_rebuild() {
*/
function template_preprocess_block(&$variables) {
$block_counter = &drupal_static(__FUNCTION__, array());
- $variables['block'] = (object) array_merge($variables['elements']['#block']->getDefinition(), $variables['elements']['#block']->getConfig());
- if (!empty($variables['elements']['#title']) && empty($variables['block']->subject)) {
- $variables['block']->subject = $variables['elements']['#title'];
- }
+
+ $variables['block'] = (object) $variables['elements']['#block_config'];
+
// All blocks get an independent counter for each region.
if (!isset($block_counter[$variables['block']->region])) {
$block_counter[$variables['block']->region] = 1;
@@ -623,14 +564,14 @@ function template_preprocess_block(&$variables) {
// We can safely explode on : because we know the Block plugin type manager
// enforces that delimiter for all derivatives.
- $parts = explode(':', $variables['elements']['#block']->getPluginId());
+ $parts = explode(':', $variables['elements']['#block']->get('plugin'));
$suggestion = 'block';
while ($part = array_shift($parts)) {
$variables['theme_hook_suggestions'][] = $suggestion .= '__' . strtr($part, '-', '_');
}
// Create a valid HTML ID and make sure it is unique.
- if (!empty($variables['block']->config_id)) {
- $config_id = explode('.', $variables['block']->config_id);
+ if ($id = $variables['elements']['#block']->id()) {
+ $config_id = explode('.', $id);
$machine_name = array_pop($config_id);
$variables['block_html_id'] = drupal_html_id('block-' . $machine_name);
$variables['theme_hook_suggestions'][] = 'block__' . $machine_name;
@@ -643,14 +584,12 @@ function template_preprocess_block(&$variables) {
* Removes deleted role from blocks that use it.
*/
function block_user_role_delete($role) {
- $block_configs = config_get_storage_names_with_prefix('plugin.core.block');
- foreach ($block_configs as $config_id) {
- $config = config($config_id);
- $roles = $config->get('visibility.role.roles');
- if (isset($roles[$role->rid])) {
- unset($roles[$role->rid]);
- $config->set('visibility.role.roles', $roles);
- $config->save();
+ foreach (entity_load_multiple('block') as $block_id => $block) {
+ $visibility = $block->get('visibility');
+ if (isset($visibility['roles']['roles'][$role->rid])) {
+ unset($visibility['roles']['roles'][$role->rid]);
+ $block->set('visibility', $visibility);
+ $block->save();
}
}
}
@@ -659,11 +598,9 @@ function block_user_role_delete($role) {
* Implements hook_menu_delete().
*/
function block_menu_delete($menu) {
- $block_configs = config_get_storage_names_with_prefix('plugin.core.block');
- foreach ($block_configs as $config_id) {
- $config = config($config_id);
- if ($config->get('id') == 'menu_menu_block:' . $menu->id()) {
- $config->delete();
+ foreach (entity_load_multiple('block') as $block_id => $block) {
+ if ($block->get('plugin') == 'menu_menu_block:' . $menu->id()) {
+ $block->delete();
}
}
}
@@ -681,35 +618,18 @@ function block_admin_paths() {
}
/**
- * Implements hook_modules_uninstalled().
- *
- * Cleans up any block configuration for uninstalled modules.
- */
-function block_modules_uninstalled($modules) {
- $block_configs = config_get_storage_names_with_prefix('plugin.core.block');
- foreach ($block_configs as $config_id) {
- $config = config($config_id);
- if (in_array($config->get('module'), $modules)) {
- $config->delete();
- }
- }
-}
-
-/**
* Implements hook_language_delete().
*
* Delete the potential block visibility settings of the deleted language.
*/
function block_language_delete($language) {
// Remove the block visibility settings for the deleted language.
- $block_configs = config_get_storage_names_with_prefix('plugin.core.block');
- foreach ($block_configs as $config_id) {
- $config = config($config_id);
- $languages = $config->get('visibility.language.langcodes');
- if (isset($languages[$language->langcode])) {
- unset($languages[$language->langcode]);
- $config->set('visibility.language.langcodes', $languages);
- $config->save();
+ foreach (entity_load_multiple('block') as $block_id => $block) {
+ $visibility = $block->get('visibility');
+ if (isset($visibility['language']['langcodes'][$language->langcode])) {
+ unset($visibility['language']['langcodes'][$language->langcode]);
+ $block->set('visibility', $visibility);
+ $block->save();
}
}
}
diff --git a/core/modules/block/custom_block/custom_block.module b/core/modules/block/custom_block/custom_block.module
index d3e1588..8c7fdea 100644
--- a/core/modules/block/custom_block/custom_block.module
+++ b/core/modules/block/custom_block/custom_block.module
@@ -19,8 +19,8 @@ function custom_block_menu() {
$items['admin/structure/block/list/' . $plugin_id . '/add/custom_blocks'] = array(
'title' => 'Add custom block',
'description' => 'Create a block with custom content and settings.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('block_admin_configure', 'custom_block:custom_block', $theme),
+ 'page callback' => 'block_admin_add',
+ 'page arguments' => array('custom_block:custom_block', $theme),
'access callback' => TRUE,
'type' => MENU_LOCAL_ACTION,
'file' => 'block.admin.inc',
diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/block/block/CustomBlock.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/block/block/CustomBlock.php
index 8b142ef..e09a3ab 100644
--- a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/block/block/CustomBlock.php
+++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/block/block/CustomBlock.php
@@ -9,6 +9,7 @@
use Drupal\block\BlockBase;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
+use Drupal\block\Plugin\Core\Entity\Block;
/**
* Defines a generic custom block type.
@@ -29,17 +30,6 @@
class CustomBlock extends BlockBase {
/**
- * Overrides \Drupal\block\BlockBase::blockSettings().
- */
- public function blockSettings() {
- // By default, use a blank block title rather than the block description
- // (which is "Custom Block").
- return array(
- 'subject' => '',
- );
- }
-
- /**
* Overrides \Drupal\block\BlockBase::getConfig().
*/
public function getConfig() {
@@ -60,7 +50,7 @@ public function getConfig() {
public function blockForm($form, &$form_state) {
// @todo Disable this field when editing an existing block and provide a
// separate interface for administering custom blocks.
- $form['custom_block']['info'] = array(
+ $form['info'] = array(
'#type' => 'textfield',
'#title' => t('Block description'),
'#required' => TRUE,
@@ -69,7 +59,7 @@ public function blockForm($form, &$form_state) {
);
// @todo Disable this field when editing an existing block and provide a
// separate interface for administering custom blocks.
- $form['custom_block']['body'] = array(
+ $form['body'] = array(
'#type' => 'text_format',
'#title' => t('Block body'),
'#default_value' => $this->configuration['body'],
@@ -78,11 +68,25 @@ public function blockForm($form, &$form_state) {
'#rows' => 15,
'#required' => TRUE,
);
- $form['custom_block']['title']['#description'] = t('The title of the block as shown to the user.');
+ $form['title']['#description'] = t('The title of the block as shown to the user.');
return $form;
}
/**
+ * Overrides \Drupal\block\BlockBase::blockValidate().
+ */
+ public function blockValidate($form, &$form_state) {
+ list(, $bid) = explode(':', $form_state['entity']->get('plugin'));
+ $custom_block_exists = (bool) db_query_range('SELECT 1 FROM {block_custom} WHERE bid <> :bid AND info = :info', 0, 1, array(
+ ':bid' => $bid,
+ ':info' => $form_state['values']['info'],
+ ))->fetchField();
+ if (empty($form_state['values']['info']) || $custom_block_exists) {
+ form_set_error('info', t('Ensure that each block description is unique.'));
+ }
+ }
+
+ /**
* Overrides \Drupal\block\BlockBase::blockSubmit().
*/
public function blockSubmit($form, &$form_state) {
@@ -94,7 +98,7 @@ public function blockSubmit($form, &$form_state) {
'bid' => is_numeric($bid) ? $bid : NULL,
);
drupal_write_record('block_custom', $block, !is_null($block['bid']) ? array('bid') : array());
- $this->configuration['id'] = 'custom_block:' . $block['bid'];
+ $form_state['entity']->set('plugin', 'custom_block:' . $block['bid']);
// Invalidate the block cache to update custom block-based derivatives.
if (module_exists('block')) {
drupal_container()->get('plugin.manager.block')->clearCachedDefinitions();
@@ -104,7 +108,7 @@ public function blockSubmit($form, &$form_state) {
/**
* Implements \Drupal\block\BlockBase::blockBuild().
*/
- public function blockBuild() {
+ public function blockBuild(Block $entity) {
// Populate the block with the user-defined block body.
return array(
'#theme' => 'custom_block_block',
diff --git a/core/modules/block/lib/Drupal/block/BlockAccessController.php b/core/modules/block/lib/Drupal/block/BlockAccessController.php
new file mode 100644
index 0000000..4bf4478
--- /dev/null
+++ b/core/modules/block/lib/Drupal/block/BlockAccessController.php
@@ -0,0 +1,26 @@
+getPlugin()->access($entity);
+ }
+
+}
diff --git a/core/modules/block/lib/Drupal/block/BlockBase.php b/core/modules/block/lib/Drupal/block/BlockBase.php
index 7d1356b..24633c0 100644
--- a/core/modules/block/lib/Drupal/block/BlockBase.php
+++ b/core/modules/block/lib/Drupal/block/BlockBase.php
@@ -8,6 +8,7 @@
namespace Drupal\block;
use Drupal\Component\Plugin\PluginBase;
+use Drupal\block\Plugin\Core\Entity\Block;
/**
* Defines a base block implementation that most blocks plugins will extend.
@@ -19,25 +20,6 @@
abstract class BlockBase extends PluginBase implements BlockInterface {
/**
- * Implements \Drupal\block\BlockInterface::settings().
- *
- * Most block plugins should not override this method. To add additional
- * settings or change the default values for setting, override
- * BlockBase::blockSettings().
- *
- * @see \Drupal\block\BlockBase::blockSettings()
- */
- public function settings() {
- $settings = $this->blockSettings();
- // By default, blocks are enabled and not cached.
- $settings += array(
- 'status' => TRUE,
- 'cache' => DRUPAL_NO_CACHE,
- );
- return $settings;
- }
-
- /**
* Returns plugin-specific settings for the block.
*
* Block plugins only need to override this method if they override the
@@ -69,7 +51,7 @@ public function getConfig() {
if (empty($this->configuration)) {
// If the plugin configuration is not already set, initialize it with the
// default settings for the block plugin.
- $this->configuration = $this->settings();
+ $this->configuration = $this->blockSettings();
// @todo This loads the default subject. Is this the right place to do so?
$definition = $this->getDefinition();
@@ -77,6 +59,8 @@ public function getConfig() {
$this->configuration += array('subject' => $definition['subject']);
}
}
+ // Ensure that the default cache mode is set.
+ $this->configuration += array('cache' => DRUPAL_NO_CACHE);
return $this->configuration;
}
@@ -131,7 +115,7 @@ public function blockAccess() {
* @see hook_block_access()
* @see \Drupal\block\BlockBase::blockAccess()
*/
- public function access() {
+ public function access($entity) {
// If the block-specific access restrictions indicate the block is not
// accessible, always deny access.
if (!$this->blockAccess()) {
@@ -142,7 +126,7 @@ public function access() {
global $user;
// Deny access to disabled blocks.
- if (empty($this->configuration['status'])) {
+ if (!$entity->get('status')) {
return FALSE;
}
@@ -150,26 +134,27 @@ public function access() {
// If a block has no roles associated, it is displayed for every role.
// For blocks with roles associated, if none of the user's roles matches
// the settings from this block, access is denied.
- if (!empty($this->configuration['visibility']['role']['roles']) && !array_intersect(array_filter($this->configuration['visibility']['role']['roles']), array_keys($user->roles))) {
+ $visibility = $entity->get('visibility');
+ if (!empty($visibility['role']['roles']) && !array_intersect(array_filter($visibility['role']['roles']), array_keys($user->roles))) {
// No match.
return FALSE;
}
// Page path handling.
// Limited visibility blocks must list at least one page.
- if (!empty($this->configuration['visibility']['path']['visibility']) && $this->configuration['visibility']['path']['visibility'] == BLOCK_VISIBILITY_LISTED && empty($this->configuration['visibility']['path']['pages'])) {
+ if (!empty($visibility['path']['visibility']) && $visibility['path']['visibility'] == BLOCK_VISIBILITY_LISTED && empty($visibility['path']['pages'])) {
return FALSE;
}
// Match path if necessary.
- if (!empty($this->configuration['visibility']['path']['pages'])) {
+ if (!empty($visibility['path']['pages'])) {
// Assume there are no matches until one is found.
$page_match = FALSE;
// Convert path to lowercase. This allows comparison of the same path
// with different case. Ex: /Page, /page, /PAGE.
- $pages = drupal_strtolower($this->configuration['visibility']['path']['pages']);
- if ($this->configuration['visibility']['path']['visibility'] < BLOCK_VISIBILITY_PHP) {
+ $pages = drupal_strtolower($visibility['path']['pages']);
+ 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));
@@ -179,10 +164,10 @@ public function access() {
// except those listed in $block->pages. When set to 1
// (BLOCK_VISIBILITY_LISTED), it is displayed only on those pages
// listed in $block->pages.
- $page_match = !($this->configuration['visibility']['path']['visibility'] xor $page_match);
+ $page_match = !($visibility['path']['visibility'] xor $page_match);
}
elseif (module_exists('php')) {
- $page_match = php_eval($this->configuration['visibility']['path']['pages']);
+ $page_match = php_eval($visibility['path']['pages']);
}
// If there are page visibility restrictions and this page does not
@@ -193,15 +178,15 @@ public function access() {
}
// Language visibility settings.
- if (!empty($this->configuration['visibility']['language']['langcodes']) && array_filter($this->configuration['visibility']['language']['langcodes'])) {
- if (empty($this->configuration['visibility']['language']['langcodes'][language($this->configuration['visibility']['language']['language_type'])->langcode])) {
+ if (!empty($visibility['language']['langcodes']) && array_filter($visibility['language']['langcodes'])) {
+ if (empty($visibility['language']['langcodes'][language($visibility['language']['language_type'])->langcode])) {
return FALSE;
}
}
// Check other modules for block access rules.
foreach (module_implements('block_access') as $module) {
- if (module_invoke($module, 'block_access', $this) === FALSE) {
+ if (module_invoke($module, 'block_access', $entity) === FALSE) {
return FALSE;
}
}
@@ -220,72 +205,43 @@ public function access() {
*
* @see \Drupal\block\BlockBase::blockForm()
*/
- public function form($form, &$form_state) {
+ public function form($form, &$form_state, $entity) {
$definition = $this->getDefinition();
- $config = $this->getConfig();
$form['id'] = array(
'#type' => 'value',
- '#value' => $definition['id'],
+ '#value' => $entity->id(),
);
$form['module'] = array(
'#type' => 'value',
'#value' => $definition['module'],
);
- // Get the block subject for the page title.
- $subject = isset($config['subject']) ? $config['subject'] : '';
-
- // Get the theme for the page title.
- $theme_default = variable_get('theme_default', 'stark');
- $admin_theme = config('system.theme')->get('admin');
- $themes = list_themes();
- $theme_key = $form['theme']['#value'];
- $theme = $themes[$theme_key];
- // Use meaningful titles for the main site and administrative themes.
- $theme_title = $theme->info['name'];
- if ($theme_key == $theme_default) {
- $theme_title = t('!theme (default theme)', array('!theme' => $theme_title));
- }
- elseif ($admin_theme && $theme_key == $admin_theme) {
- $theme_title = t('!theme (administration theme)', array('!theme' => $theme_title));
- }
-
- if ($subject) {
- drupal_set_title(t("%subject block in %theme", array('%subject' => $subject, '%theme' => $theme_title)), PASS_THROUGH);
- }
-
- $form['settings'] = array(
- '#weight' => -5,
- );
- $form['settings']['title'] = array(
+ $form['label'] = array(
'#type' => 'textfield',
'#title' => t('Block title'),
'#maxlength' => 255,
- '#default_value' => isset($subject) ? $subject : '',
+ '#default_value' => !$entity->isNew() ? $entity->label() : $definition['subject'],
);
- $form['settings']['machine_name'] = array(
+ $form['machine_name'] = array(
'#type' => 'textfield',
'#title' => t('Block machine name'),
'#maxlength' => 64,
'#description' => t('A unique name to save this block configuration. Must be alpha-numeric and be underscore separated.'),
- '#default_value' => isset($config['config_id']) ? $config['config_id'] : '',
+ '#default_value' => $entity->id(),
'#required' => TRUE,
+ '#disabled' => !$entity->isNew(),
);
- if (isset($config['config_id'])) {
- $form['settings']['machine_name']['#disabled'] = TRUE;
- }
// Region settings.
$form['region'] = array(
'#type' => 'select',
'#title' => t('Region'),
'#description' => t('Select the region where this block should be displayed.'),
- '#default_value' => !empty($config['region']) && $config['region'] != -1 ? $config['region'] : NULL,
+ '#default_value' => $entity->get('region'),
'#empty_value' => BLOCK_REGION_NONE,
- '#options' => system_region_list($theme_key, REGIONS_VISIBLE),
+ '#options' => system_region_list($entity->get('theme'), REGIONS_VISIBLE),
);
-
// Visibility settings.
$form['visibility'] = array(
'#type' => 'vertical_tabs',
@@ -309,15 +265,16 @@ public function form($form, &$form_state) {
// @todo remove this access check and inject it in some other way. In fact
// this entire visibility settings section probably needs a separate user
// interface in the near future.
+ $visibility = $entity->get('visibility');
$access = user_access('use PHP for settings');
- if (!empty($config['visibility']['path']['visibility']) && $config['visibility']['path']['visibility'] == BLOCK_VISIBILITY_PHP && !$access) {
+ if (!empty($visibility['path']['visibility']) && $visibility['path']['visibility'] == BLOCK_VISIBILITY_PHP && !$access) {
$form['visibility']['path']['visibility'] = array(
'#type' => 'value',
'#value' => BLOCK_VISIBILITY_PHP,
);
$form['visibility']['path']['pages'] = array(
'#type' => 'value',
- '#value' => !empty($config['visibility']['path']['pages']) ? $config['visibility']['path']['pages'] : '',
+ '#value' => !empty($visibility['path']['pages']) ? $visibility['path']['pages'] : '',
);
}
else {
@@ -339,12 +296,12 @@ public function form($form, &$form_state) {
'#type' => 'radios',
'#title' => t('Show block on specific pages'),
'#options' => $options,
- '#default_value' => !empty($this->configuration['visibility']['path']['visibility']) ? $this->configuration['visibility']['path']['visibility'] : BLOCK_VISIBILITY_NOTLISTED,
+ '#default_value' => !empty($visibility['path']['visibility']) ? $visibility['path']['visibility'] : BLOCK_VISIBILITY_NOTLISTED,
);
$form['visibility']['path']['pages'] = array(
'#type' => 'textarea',
'#title' => '' . $title . '',
- '#default_value' => !empty($this->configuration['visibility']['path']['pages']) ? $this->configuration['visibility']['path']['pages'] : '',
+ '#default_value' => !empty($visibility['path']['pages']) ? $visibility['path']['pages'] : '',
'#description' => $description,
);
}
@@ -379,13 +336,13 @@ public function form($form, &$form_state) {
'#type' => 'radios',
'#title' => t('Language type'),
'#options' => $language_type_options,
- '#default_value' => !empty($this->configuration['visibility']['language']['language_type']) ? $this->configuration['visibility']['language']['language_type'] : $configurable_language_types[0],
+ '#default_value' => !empty($visibility['language']['language_type']) ? $visibility['language']['language_type'] : $configurable_language_types[0],
'#access' => count($language_type_options) > 1,
);
$form['visibility']['language']['langcodes'] = array(
'#type' => 'checkboxes',
'#title' => t('Show this block only for specific languages'),
- '#default_value' => !empty($this->configuration['visibility']['language']['langcodes']) ? $this->configuration['visibility']['language']['langcodes'] : array(),
+ '#default_value' => !empty($visibility['language']['langcodes']) ? $visibility['language']['langcodes'] : array(),
'#options' => $langcodes_options,
'#description' => t('Show this block only for the selected language(s). If you select no languages, the block will be visibile in all languages.'),
);
@@ -403,20 +360,13 @@ public function form($form, &$form_state) {
$form['visibility']['role']['roles'] = array(
'#type' => 'checkboxes',
'#title' => t('Show block for specific roles'),
- '#default_value' => !empty($this->configuration['visibility']['role']['roles']) ? $this->configuration['visibility']['role']['roles'] : array(),
+ '#default_value' => !empty($visibility['role']['roles']) ? $visibility['role']['roles'] : array(),
'#options' => $role_options,
'#description' => t('Show this block only for the selected role(s). If you select no roles, the block will be visible to all users.'),
);
- // Add specific configuration for this block type.
- $form += $this->blockForm($form, $form_state);
-
- $form['actions'] = array('#type' => 'actions');
- $form['actions']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Save block'),
- );
-
+ // Add plugin-specific settings for this block type.
+ $form['settings'] = $this->blockForm(array(), $form_state);
return $form;
}
@@ -451,30 +401,19 @@ public function blockForm($form, &$form_state) {
* @see \Drupal\block\BlockBase::blockValidate()
*/
public function validate($form, &$form_state) {
- if (empty($form['settings']['machine_name']['#disabled'])) {
+ if (empty($form['machine_name']['#disabled'])) {
if (preg_match('/[^a-zA-Z0-9_]/', $form_state['values']['machine_name'])) {
form_set_error('machine_name', t('Block name must be alphanumeric or underscores only.'));
}
- if (in_array('plugin.core.block.' . $form_state['values']['machine_name'], config_get_storage_names_with_prefix('plugin.core.block'))) {
- form_set_error('machine_name', t('Block name must be unique.'));
- }
}
else {
$config_id = explode('.', $form_state['values']['machine_name']);
$form_state['values']['machine_name'] = array_pop($config_id);
}
- if ($form_state['values']['module'] == 'block') {
- $custom_block_exists = (bool) db_query_range('SELECT 1 FROM {block_custom} WHERE bid <> :bid AND info = :info', 0, 1, array(
- ':bid' => $form_state['values']['delta'],
- ':info' => $form_state['values']['info'],
- ))->fetchField();
- if (empty($form_state['values']['info']) || $custom_block_exists) {
- form_set_error('info', t('Ensure that each block description is unique.'));
- }
- }
$form_state['values']['visibility']['role']['roles'] = array_filter($form_state['values']['visibility']['role']['roles']);
-
- // Perform block type-specific validation.
+ if ($form_state['entity']->isNew()) {
+ form_set_value($form['id'], $form_state['values']['theme'] . '.' . $form_state['values']['machine_name'], $form_state);
+ }
$this->blockValidate($form, $form_state);
}
@@ -508,32 +447,11 @@ public function blockValidate($form, &$form_state) {}
*/
public function submit($form, &$form_state) {
if (!form_get_errors()) {
- $transaction = db_transaction();
- try {
- $keys = array(
- 'visibility' => 'visibility',
- 'pages' => 'pages',
- 'title' => 'subject',
- 'module' => 'module',
- 'region' => 'region',
- );
- foreach ($keys as $key => $new_key) {
- if (isset($form_state['values'][$key])) {
- $this->configuration[$new_key] = $form_state['values'][$key];
- }
- }
- }
- catch (Exception $e) {
- $transaction->rollback();
- watchdog_exception('block', $e);
- throw $e;
- }
- if (empty($this->configuration['weight'])) {
- $this->configuration['weight'] = 0;
- }
-
- // Perform block type-specific validation.
$this->blockSubmit($form, $form_state);
+
+ drupal_set_message(t('The block configuration has been saved.'));
+ cache_invalidate_tags(array('content' => TRUE));
+ $form_state['redirect'] = 'admin/structure/block/list/block_plugin_ui:' . $form_state['entity']->get('theme');
}
}
@@ -555,46 +473,4 @@ public function submit($form, &$form_state) {
*/
public function blockSubmit($form, &$form_state) {}
- /**
- * Implements \Drupal\block\BlockInterface::build().
- *
- * Allows blocks to be altered after they are built.
- *
- * Most block plugins should not override this method. To define how a
- * particular block is rendered, implement the abstract method
- * BlockBase::blockBuild().
- *
- * @return array $build
- * A renderable array of data.
- * - #title: The default localized title of the block.
- *
- * @todo Add specific examples of $id and $name below.
- *
- * @see \Drupal\block\BlockBase::blockBuild()
- */
- public function build() {
- // Allow modules to modify the block before it is viewed, via either
- // hook_block_view_alter(), hook_block_view_ID_alter(), or
- // hook_block_view_NAME_alter().
- $id = str_replace(':', '__', $this->getPluginId());
-
- $config = $this->getConfig();
- $config_id = explode('.', $config['config_id']);
- $name = array_pop($config_id);
-
- $build = $this->blockBuild();
- drupal_alter(array('block_view', "block_view_$id", "block_view_$name"), $build, $this);
- return $build;
- }
-
- /**
- * Builds the renderable array for a specific block type.
- *
- * @return array
- * A renderable array representing the output of the block.
- *
- * @see \Drupal\block\BlockBase::build()
- */
- abstract public function blockBuild();
-
}
diff --git a/core/modules/block/lib/Drupal/block/BlockFormController.php b/core/modules/block/lib/Drupal/block/BlockFormController.php
new file mode 100644
index 0000000..0ad4d4a
--- /dev/null
+++ b/core/modules/block/lib/Drupal/block/BlockFormController.php
@@ -0,0 +1,59 @@
+getPlugin()->form($form, $form_state, $entity);
+ }
+
+ /**
+ * Overrides \Drupal\Core\Entity\EntityFormController::actions().
+ */
+ protected function actions(array $form, array &$form_state) {
+ $actions = parent::actions($form, $form_state);
+ $actions['submit']['#value'] = t('Save block');
+ return $actions;
+ }
+
+ /**
+ * Overrides \Drupal\Core\Entity\EntityFormController::validate().
+ */
+ public function validate(array $form, array &$form_state) {
+ parent::validate($form, $form_state);
+
+ $entity = $this->getEntity($form_state);
+ $entity->getPlugin()->validate($form, $form_state);
+ }
+
+ /**
+ * Overrides \Drupal\Core\Entity\EntityFormController::submit().
+ */
+ public function submit(array $form, array &$form_state) {
+ parent::submit($form, $form_state);
+
+ $entity = $this->getEntity($form_state);
+ // Call the plugin submit handler.
+ $entity->getPlugin()->submit($form, $form_state);
+
+ // Save the settings of the plugin.
+ $entity->set('settings', $entity->getPlugin()->getConfig());
+ $entity->save();
+ }
+
+}
diff --git a/core/modules/block/lib/Drupal/block/BlockInterface.php b/core/modules/block/lib/Drupal/block/BlockInterface.php
index b419b27..8f267d2 100644
--- a/core/modules/block/lib/Drupal/block/BlockInterface.php
+++ b/core/modules/block/lib/Drupal/block/BlockInterface.php
@@ -1,11 +1,14 @@
theme) {
+ $this->theme = $GLOBALS['theme'];
+ }
+
+ // 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);
+ uasort($entities, 'static::sort');
+ return $entities;
+ }
+
+ /**
+ * Overrides \Drupal\Core\Entity\EntityListController::render().
+ */
+ public function render($theme = NULL) {
+ // If no theme was specified, use the current theme.
+ $this->theme = $theme ?: $GLOBALS['theme_key'];
+
+ $form_state = array();
+ $form_state['build_info']['args'] = array();
+ $form_state['build_info']['callback'] = array($this, 'form');
+ return drupal_build_form('block_admin_display_form', $form_state);
+ }
+
+ /**
+ * Sorts active blocks by region then weight; sorts inactive blocks by name.
+ */
+ protected function sort(Block $a, Block $b) {
+ static $regions;
+ // We need the region list to correctly order by region.
+ if (!isset($regions)) {
+ $regions = array_flip(array_keys($this->regions));
+ $regions[BLOCK_REGION_NONE] = count($regions);
+ }
+
+ // Separate enabled from disabled.
+ $status = $b->get('status') - $a->get('status');
+ if ($status) {
+ return $status;
+ }
+ // Sort by region (in the order defined by theme .info file).
+ $aregion = $a->get('region');
+ $bregion = $b->get('region');
+ if ((!empty($aregion) && !empty($bregion)) && ($place = ($regions[$aregion] - $regions[$bregion]))) {
+ return $place;
+ }
+ // Sort by weight, unless disabled.
+ if ($a->get('region') != BLOCK_REGION_NONE) {
+ $weight = $a->get('weight') - $b->get('weight');
+ if ($weight) {
+ return $weight;
+ }
+ }
+ // Sort by label.
+ return strcmp($a->label(), $b->label());
+ }
+
+ /**
+ * Form constructor for the main block administration form.
+ */
+ public function form($form, &$form_state) {
+ $entities = $this->load();
+ $form['#attached']['css'][] = drupal_get_path('module', 'block') . '/block.admin.css';
+ $form['#attached']['library'][] = array('system', 'drupal.tableheader');
+ $form['#attached']['library'][] = array('block', 'drupal.block');
+
+ // Add a last region for disabled blocks.
+ $block_regions_with_disabled = $this->regions + array(BLOCK_REGION_NONE => BLOCK_REGION_NONE);
+
+ foreach ($block_regions_with_disabled as $region => $title) {
+ $form['#attached']['drupal_add_tabledrag'][] = array('blocks', 'match', 'sibling', 'block-region-select', 'block-region-' . $region, NULL, FALSE);
+ $form['#attached']['drupal_add_tabledrag'][] = array('blocks', 'order', 'sibling', 'block-weight', 'block-weight-' . $region);
+ }
+ $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'] = array();
+ $form['#tree'] = TRUE;
+
+ foreach ($entities as $entity_id => $entity) {
+ $info = $entity->getPlugin()->getDefinition();
+ $form['blocks'][$entity_id]['info'] = array(
+ '#markup' => check_plain($info['subject']),
+ );
+ $form['blocks'][$entity_id]['theme'] = array(
+ '#type' => 'hidden',
+ '#value' => $this->theme,
+ );
+ $form['blocks'][$entity_id]['weight'] = array(
+ '#type' => 'weight',
+ '#default_value' => $entity->get('weight'),
+ '#delta' => $weight_delta,
+ '#title_display' => 'invisible',
+ '#title' => t('Weight for @block block', array('@block' => $info['subject'])),
+ );
+ $form['blocks'][$entity_id]['region'] = array(
+ '#type' => 'select',
+ '#default_value' => $entity->get('region') != BLOCK_REGION_NONE ? $entity->get('region') : NULL,
+ '#empty_value' => BLOCK_REGION_NONE,
+ '#title_display' => 'invisible',
+ '#title' => t('Region for @block block', array('@block' => $info['subject'])),
+ '#options' => $this->regions,
+ );
+ $links['configure'] = array(
+ 'title' => t('configure'),
+ 'href' => 'admin/structure/block/manage/' . $entity_id . '/configure',
+ );
+ $links['delete'] = array(
+ 'title' => t('delete'),
+ 'href' => 'admin/structure/block/manage/' . $entity_id . '/delete',
+ );
+ $form['blocks'][$entity_id]['operations'] = array(
+ '#type' => 'operations',
+ '#links' => $links,
+ );
+ }
+ // 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;
+ }
+
+ $form['actions'] = array(
+ '#tree' => FALSE,
+ '#type' => 'actions',
+ );
+ $form['actions']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Save blocks'),
+ '#button_type' => 'primary',
+ '#submit' => array(array($this, 'submit')),
+ );
+ return $form;
+ }
+
+ /**
+ * Form submission handler for the main block administration form.
+ */
+ public function submit($form, &$form_state) {
+ $entities = entity_load_multiple('block', array_keys($form_state['values']['blocks']));
+ foreach ($entities as $entity_id => $entity) {
+ $entity->set('weight', $form_state['values']['blocks'][$entity_id]['weight']);
+ $entity->set('region', $form_state['values']['blocks'][$entity_id]['region']);
+ $entity->save();
+ }
+ drupal_set_message(t('The block settings have been updated.'));
+ cache_invalidate_tags(array('content' => TRUE));
+ }
+
+}
diff --git a/core/modules/block/lib/Drupal/block/BlockRenderController.php b/core/modules/block/lib/Drupal/block/BlockRenderController.php
new file mode 100644
index 0000000..416c52d
--- /dev/null
+++ b/core/modules/block/lib/Drupal/block/BlockRenderController.php
@@ -0,0 +1,90 @@
+ $entity,
+ '#weight' => $entity->get('weight'),
+ '#theme_wrappers' => array('block'),
+ '#block_config' => array(
+ 'id' => $entity->get('plugin'),
+ 'region' => $entity->get('region'),
+ 'module' => $entity->get('module'),
+ 'subject' => $entity->label(),
+ ),
+ );
+ }
+
+ /**
+ * Implements Drupal\Core\Entity\EntityRenderControllerInterface::view().
+ */
+ public function view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL) {
+ $build = $this->viewMultiple(array($entity), $view_mode, $langcode);
+ return reset($build);
+ }
+
+ /**
+ * Implements Drupal\Core\Entity\EntityRenderControllerInterface::viewMultiple().
+ */
+ public function viewMultiple(array $entities = array(), $view_mode = 'full', $langcode = NULL) {
+ $build = array();
+ foreach ($entities as $entity_id => $entity) {
+ $build[$entity_id] = $entity->getPlugin()->blockBuild($entity);
+ // Allow blocks to be empty, do not add in the defaults.
+ if (!empty($build[$entity_id])) {
+ $build[$entity_id] = $this->getBuildDefaults($entity, $view_mode, $langcode) + $build[$entity_id];
+ }
+
+ // All blocks, even when empty, should be available for altering.
+ $id = str_replace(':', '__', $entity->get('plugin'));
+ list(, $name) = $entity->id();
+ drupal_alter(array('block_view', "block_view_$id", "block_view_$name"), $build[$entity_id], $entity);
+
+ }
+ return $build;
+ }
+
+}
diff --git a/core/modules/block/lib/Drupal/block/BlockStorageController.php b/core/modules/block/lib/Drupal/block/BlockStorageController.php
new file mode 100644
index 0000000..a873c5d
--- /dev/null
+++ b/core/modules/block/lib/Drupal/block/BlockStorageController.php
@@ -0,0 +1,56 @@
+get('module')) {
+ $definition = $entity->getPlugin()->getDefinition();
+ $entity->set('module', $definition['module']);
+ }
+
+ return $entity;
+ }
+
+ /**
+ * Overrides \Drupal\Core\Config\Entity\ConfigStorageController::load().
+ */
+ public function load(array $ids = NULL) {
+ $entities = parent::load($ids);
+ // Only blocks with a valid plugin should be loaded.
+ return array_filter($entities, function ($entity) {
+ return $entity->getPlugin();
+ });
+ }
+
+ /**
+ * Overrides \Drupal\Core\Config\Entity\ConfigStorageController::loadByProperties().
+ */
+ public function loadByProperties(array $values = array()) {
+ $blocks = $this->load();
+ foreach ($values as $key => $value) {
+ $blocks = array_filter($blocks, function($block) use ($key, $value) {
+ return $value === $block->get($key);
+ });
+ }
+ return $blocks;
+ }
+
+}
diff --git a/core/modules/block/lib/Drupal/block/Plugin/Core/Entity/Block.php b/core/modules/block/lib/Drupal/block/Plugin/Core/Entity/Block.php
new file mode 100644
index 0000000..9dffe3c
--- /dev/null
+++ b/core/modules/block/lib/Drupal/block/Plugin/Core/Entity/Block.php
@@ -0,0 +1,194 @@
+instance) {
+ // Throw an exception if no plugin string was provided.
+ if (!$this->plugin) {
+ throw new PluginException(format_string("The block '@block' did not specify a plugin.", array('@block' => $this->id())));
+ }
+
+ // Create a plugin instance and store its configuration as settings.
+ try {
+ $this->instance = drupal_container()->get('plugin.manager.block')->createInstance($this->plugin, $this->settings);
+ $this->settings += $this->instance->getConfig();
+ }
+ catch (PluginException $e) {
+ // Ignore blocks belonging to disabled modules, but re-throw valid
+ // exceptions when the module is enabled and the plugin is misconfigured.
+ if (empty($this->module) || module_exists($this->module)) {
+ throw $e;
+ }
+ }
+ }
+ return $this->instance;
+ }
+
+ /**
+ * Overrides \Drupal\Core\Entity\Entity::uri();
+ */
+ public function uri() {
+ return array(
+ 'path' => 'admin/structure/block/manage/' . $this->id(),
+ 'options' => array(
+ 'entity_type' => $this->entityType,
+ 'entity' => $this,
+ ),
+ );
+ }
+
+ /**
+ * Overrides \Drupal\Core\Config\Entity\ConfigEntityBase::get();
+ */
+ public function get($property_name, $langcode = NULL) {
+ // The theme is stored in the entity ID.
+ $value = parent::get($property_name, $langcode);
+ if ($property_name == 'theme' && !$value) {
+ list($value) = explode('.', $this->id());
+ }
+ return $value;
+ }
+
+ /**
+ * Overrides \Drupal\Core\Config\Entity\ConfigEntityBase::getExportProperties();
+ */
+ public function getExportProperties() {
+ $names = array(
+ 'id',
+ 'label',
+ 'uuid',
+ 'region',
+ 'weight',
+ 'module',
+ 'status',
+ 'visibility',
+ 'plugin',
+ 'settings',
+ );
+ $properties = array();
+ foreach ($names as $name) {
+ $properties[$name] = $this->get($name);
+ }
+ return $properties;
+ }
+
+}
diff --git a/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php b/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php
index b7186b0..181d32c 100644
--- a/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php
+++ b/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php
@@ -12,7 +12,6 @@
use Drupal\Core\Plugin\Discovery\AlterDecorator;
use Drupal\Core\Plugin\Discovery\CacheDecorator;
use Drupal\Component\Plugin\Factory\DefaultFactory;
-use Drupal\Core\Plugin\Mapper\ConfigMapper;
/**
* Manages discovery and instantiation of block plugins.
@@ -32,7 +31,6 @@ public function __construct() {
$this->discovery = new AlterDecorator($this->discovery, 'block');
$this->discovery = new CacheDecorator($this->discovery, 'block_plugins:' . language(LANGUAGE_TYPE_INTERFACE)->langcode, 'cache_block');
$this->factory = new DefaultFactory($this);
- $this->mapper = new ConfigMapper($this);
}
}
diff --git a/core/modules/block/lib/Drupal/block/Plugin/system/plugin_ui/BlockPluginUI.php b/core/modules/block/lib/Drupal/block/Plugin/system/plugin_ui/BlockPluginUI.php
index 27256a2..baecaa6 100644
--- a/core/modules/block/lib/Drupal/block/Plugin/system/plugin_ui/BlockPluginUI.php
+++ b/core/modules/block/lib/Drupal/block/Plugin/system/plugin_ui/BlockPluginUI.php
@@ -17,7 +17,7 @@
* id = "block_plugin_ui",
* module = "block",
* all_plugins = @Translation("All Blocks"),
- * config_path = "admin/structure/block/manage",
+ * config_path = "admin/structure/block/add",
* default_task = TRUE,
* derivative = "Drupal\block\Plugin\Derivative\BlockPluginUI",
* facets = {
@@ -116,7 +116,7 @@ public function formValidate($form, &$form_state) {
* Overrides \Drupal\system\Plugin\PluginUIBase::formSubmit().
*/
public function formSubmit($form, &$form_state) {
- $form_state['redirect'] = 'admin/structure/block/manage/' . $form_state['values']['block'] . '/' . $form_state['values']['theme'];
+ $form_state['redirect'] = 'admin/structure/block/add/' . $form_state['values']['block'] . '/' . $form_state['values']['theme'];
}
/**
diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockCacheTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockCacheTest.php
index f40d4fa..96f9343 100644
--- a/core/modules/block/lib/Drupal/block/Tests/BlockCacheTest.php
+++ b/core/modules/block/lib/Drupal/block/Tests/BlockCacheTest.php
@@ -24,6 +24,7 @@ class BlockCacheTest extends WebTestBase {
protected $admin_user;
protected $normal_user;
protected $normal_user_alt;
+ protected $block;
public static function getInfo() {
return array(
@@ -49,8 +50,7 @@ function setUp() {
$this->normal_user_alt->save();
// Enable our test block.
- $block = $this->drupalPlaceBlock('test_cache');
- $this->block_config_id = $block['config_id'];
+ $this->block = $this->drupalPlaceBlock('test_cache');
}
/**
@@ -192,15 +192,10 @@ function testCachePerPage() {
* Private helper method to set the test block's cache mode.
*/
private function setCacheMode($cache_mode) {
- $block_config = config($this->block_config_id);
- $block_config->set('cache', $cache_mode);
- $block_config->save();
-
- $instance = block_load($this->block_config_id);
- $config = $instance->getConfig();
- if ($config['cache'] != $cache_mode) {
- $this->fail(t('Unable to set cache mode to %mode. Current mode: %current_mode', array('%mode' => $cache_mode, '%current_mode' => $config['cache'])));
- }
- $this->assertEqual($config['cache'], $cache_mode, t("Test block's database entry updated to DRUPAL_NO_CACHE."));
+ $settings = $this->block->get('settings');
+ $settings['cache'] = $cache_mode;
+ $this->block->set('settings', $settings);
+ $this->block->save();
}
+
}
diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockInvalidRegionTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockInvalidRegionTest.php
index ec41b39..54417f8 100644
--- a/core/modules/block/lib/Drupal/block/Tests/BlockInvalidRegionTest.php
+++ b/core/modules/block/lib/Drupal/block/Tests/BlockInvalidRegionTest.php
@@ -46,11 +46,10 @@ function setUp() {
function testBlockInInvalidRegion() {
// Enable a test block and place it in an invalid region.
$block = $this->drupalPlaceBlock('test_html_id');
- $config = config($block['config_id']);
- $config->set('region', 'invalid_region');
- $config->save();
+ $block->set('region', 'invalid_region');
+ $block->save();
- $warning_message = t('The block %info was assigned to the invalid region %region and has been disabled.', array('%info' => $config->get('id'), '%region' => 'invalid_region'));
+ $warning_message = t('The block %info was assigned to the invalid region %region and has been disabled.', array('%info' => $block->id(), '%region' => 'invalid_region'));
// Clearing the cache should disable the test block placed in the invalid region.
$this->drupalPost('admin/config/development/performance', array(), 'Clear all caches');
@@ -61,8 +60,9 @@ function testBlockInInvalidRegion() {
$this->assertNoRaw($warning_message, 'Disabled block in the invalid region will not trigger the warning.');
// Place disabled test block in the invalid region of the default theme.
- $config->set('region', 'invalid_region');
- $config->save();
+ $block = entity_load('block', $block->id());
+ $block->set('region', 'invalid_region');
+ $block->save();
// Clear the cache to check if the warning message is not triggered.
$this->drupalPost('admin/config/development/performance', array(), 'Clear all caches');
diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockLanguageTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockLanguageTest.php
index 2fa1d40..b9ac714 100644
--- a/core/modules/block/lib/Drupal/block/Tests/BlockLanguageTest.php
+++ b/core/modules/block/lib/Drupal/block/Tests/BlockLanguageTest.php
@@ -55,7 +55,7 @@ function setUp() {
public function testLanguageBlockVisibility() {
// Check if the visibility setting is available.
$default_theme = variable_get('theme_default', 'stark');
- $this->drupalGet('admin/structure/block/manage/system_powered_by_block' . '/' . $default_theme);
+ $this->drupalGet('admin/structure/block/add/system_powered_by_block' . '/' . $default_theme);
$this->assertField('visibility[language][langcodes][en]', 'Language visibility field is visible.');
@@ -65,7 +65,7 @@ public function testLanguageBlockVisibility() {
'machine_name' => $this->randomName(8),
'region' => 'sidebar_first',
);
- $this->drupalPost('admin/structure/block/manage/system_powered_by_block' . '/' . $default_theme, $edit, t('Save block'));
+ $this->drupalPost('admin/structure/block/add/system_powered_by_block' . '/' . $default_theme, $edit, t('Save block'));
// Change the default language.
$edit = array(
@@ -89,19 +89,23 @@ public function testLanguageBlockVisibility() {
* Tests if the visibility settings are removed if the language is deleted.
*/
public function testLanguageBlockVisibilityLanguageDelete() {
-
- $default_theme = variable_get('theme_default', 'stark');
// Enable a standard block and set the visibility setting for one language.
$edit = array(
- 'visibility[language][langcodes][fr]' => TRUE,
+ 'visibility' => array(
+ 'language' => array(
+ 'language_type' => 'language_interface',
+ 'langcodes' => array(
+ 'fr' => 'fr',
+ ),
+ ),
+ ),
'machine_name' => 'language_block_test',
- 'region' => 'sidebar_first',
);
- $this->drupalPost('admin/structure/block/manage/system_powered_by_block' . '/' . $default_theme, $edit, t('Save block'));
+ $block = $this->drupalPlaceBlock('system_powered_by_block', $edit);
// Check that we have the language in config after saving the setting.
- $config = config('plugin.core.block.' . $default_theme . '.language_block_test');
- $setting = $config->get('visibility.language.langcodes.fr');
+ $visibility = $block->get('visibility');
+ $setting = $visibility['language']['langcodes']['fr'];
$this->assertTrue('fr' === $setting, 'Language is set in the block configuration.');
// Delete the language.
@@ -109,9 +113,9 @@ public function testLanguageBlockVisibilityLanguageDelete() {
// Check that the language is no longer stored in the configuration after
// it is deleted.
- $config = config('plugin.core.block.' . $default_theme . '.language_block_test');
- $setting = $config->get('visibility.language.langcodes.fr');
- $this->assertTrue(empty($setting), 'Language is no longer not set in the block configuration after deleting the block.');
+ $block = entity_load('block', $block->id());
+ $visibility = $block->get('visibility');
+ $this->assertTrue(empty($visibility['language']['langcodes']['fr']), 'Language is no longer not set in the block configuration after deleting the block.');
}
}
diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockLibrarySearchTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockLibrarySearchTest.php
index dc93755..22f47e8 100644
--- a/core/modules/block/lib/Drupal/block/Tests/BlockLibrarySearchTest.php
+++ b/core/modules/block/lib/Drupal/block/Tests/BlockLibrarySearchTest.php
@@ -54,6 +54,7 @@ function testBlockLibrarySearch() {
// Check that the block search form redirects to the correct block form.
$this->drupalPost('admin/structure/block/list/block_plugin_ui:stark/add', array('block' => 'system_main_block'), t('Next'));
- $this->assertUrl('admin/structure/block/manage/system_main_block/stark');
+ $this->assertUrl('admin/structure/block/add/system_main_block/stark');
}
+
}
diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php
new file mode 100644
index 0000000..6695681
--- /dev/null
+++ b/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php
@@ -0,0 +1,206 @@
+ 'Block storage',
+ 'description' => 'Tests the storage of blocks.',
+ 'group' => 'Block'
+ );
+ }
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->enableModules(array('block'));
+ $this->controller = entity_get_controller('block');
+ }
+
+ /**
+ * Tests CRUD operations.
+ */
+ public function testBlockCRUD() {
+ $this->assertTrue($this->controller instanceof BlockStorageController, 'The block storage controller is loaded.');
+
+ // Run each test method in the same installation.
+ $this->createTests();
+ $this->loadTests();
+ $this->renderTests();
+ $this->deleteTests();
+ }
+
+ /**
+ * Tests the creation of blocks.
+ */
+ protected function createTests() {
+ // Attempt to create a block without a plugin.
+ try {
+ $entity = $this->controller->create(array());
+ $this->fail('A block without a plugin was created with no exception thrown.');
+ }
+ catch (PluginException $e) {
+ $this->assertEqual('The block \'\' did not specify a plugin.', $e->getMessage(), 'An exception was thrown when a block was created without a plugin.');
+ }
+
+ // Create a block with only required values.
+ $entity = $this->controller->create(array(
+ 'id' => 'stark.test_block',
+ 'plugin' => 'test_html_id',
+ ));
+ $entity->save();
+
+ $this->assertTrue($entity instanceof Block, 'The newly created entity is a Block.');
+
+ // Verify all of the block properties.
+ $actual_properties = config('plugin.core.block.stark.test_block')->get();
+ $this->assertTrue(!empty($actual_properties['uuid']), 'The block UUID is set.');
+ unset($actual_properties['uuid']);
+
+ // Ensure that default values are filled in.
+ $expected_properties = array(
+ 'id' => 'stark.test_block',
+ 'label' => '',
+ 'region' => '-1',
+ 'weight' => '',
+ 'module' => 'block_test',
+ 'status' => '1',
+ 'visibility' => array(),
+ 'plugin' => 'test_html_id',
+ 'settings' => array(
+ 'cache' => '1',
+ 'subject' => t('Test block html id'),
+ ),
+ );
+ $this->assertIdentical($actual_properties, $expected_properties, 'The block properties are exported correctly.');
+
+ $this->assertTrue($entity->getPlugin() instanceof TestHtmlIdBlock, 'The entity has an instance of the correct block plugin.');
+ }
+
+ /**
+ * Tests the rendering of blocks.
+ */
+ protected function loadTests() {
+ $entities = $this->controller->load(array('stark.test_block'));
+ $entity = reset($entities);
+
+ $this->assertTrue($entity instanceof Block, 'The loaded entity is a Block.');
+
+ // Verify several properties of the block.
+ $this->assertEqual($entity->get('region'), '-1');
+ $this->assertTrue($entity->get('status'));
+ $this->assertEqual($entity->get('theme'), 'stark');
+ $this->assertEqual($entity->get('module'), 'block_test');
+ $this->assertTrue($entity->uuid());
+ }
+
+ /**
+ * Tests the rendering of blocks.
+ */
+ protected function renderTests() {
+ $entity = $this->controller->create(array(
+ 'id' => 'stark.test_block',
+ 'plugin' => 'test_html_id',
+ ));
+
+ // Test the rendering of a block.
+ $output = entity_view($entity, 'block');
+ $expected = array();
+ $expected[] = '
';
+ $expected[] = '';
+ $expected[] = ' ';
+ $expected[] = '
';
+ $expected[] = '
';
+ $expected[] = '
';
+ $expected[] = '';
+ $expected_output = implode("\n", $expected);
+ $this->assertEqual(drupal_render($output), $expected_output, 'The block rendered correctly.');
+
+ // Reset the HTML IDs so that the next render is not affected.
+ drupal_static_reset('drupal_html_id');
+
+ // Test the rendering of a block with a given title.
+ $entity->set('label', 'Powered by Bananas');
+ $output = entity_view($entity, 'block');
+ $expected = array();
+ $expected[] = ' ';
+ $expected[] = '';
+ $expected[] = '
Powered by Bananas
';
+ $expected[] = ' ';
+ $expected[] = '
';
+ $expected[] = '
';
+ $expected[] = '
';
+ $expected[] = '';
+ $expected_output = implode("\n", $expected);
+ $this->assertEqual(drupal_render($output), $expected_output, 'The block rendered correctly.');
+ }
+
+ /**
+ * Tests the deleting of blocks.
+ */
+ protected function deleteTests() {
+ $entities = $this->controller->load(array('stark.test_block'));
+ $entity = reset($entities);
+
+ // Ensure that the storage isn't currently empty.
+ $config_storage = $this->container->get('config.storage');
+ $config = $config_storage->listAll('plugin.core.block.');
+ $this->assertFalse(empty($config), 'There are blocks in config storage.');
+
+ // Delete the block.
+ $entity->delete();
+
+ // Ensure that the storage is now empty.
+ $config = $config_storage->listAll('plugin.core.block.');
+ $this->assertTrue(empty($config), 'There are no blocks in config storage.');
+ }
+
+ /**
+ * Tests the installation of default blocks.
+ */
+ public function testDefaultBlocks() {
+ $entities = $this->controller->load();
+ $this->assertTrue(empty($entities), 'There are no blocks initially.');
+
+ // Install the block_test.module, so that its default config is installed.
+ $this->enableModules(array('block_test'));
+
+ $entities = $this->controller->load();
+ $entity = reset($entities);
+ $this->assertEqual($entity->id(), 'stark.test_block', 'The default test block was loaded.');
+ }
+
+}
diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockTemplateSuggestionsUnitTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockTemplateSuggestionsUnitTest.php
index fd75adf..c469eb6 100644
--- a/core/modules/block/lib/Drupal/block/Tests/BlockTemplateSuggestionsUnitTest.php
+++ b/core/modules/block/lib/Drupal/block/Tests/BlockTemplateSuggestionsUnitTest.php
@@ -37,18 +37,25 @@ function testBlockThemeHookSuggestions() {
// an underscore (not transformed) and a hyphen (transformed to underscore),
// and generates possibilities for each level of derivative.
// @todo Clarify this comment.
- $data = array(
+ $block = entity_create('block', array(
+ 'plugin' => 'system_menu_block:menu-admin',
'region' => 'footer',
- );
+ 'id' => variable_get('theme_default', 'stark') . '.machinename',
+ ));
- $block = drupal_container()->get('plugin.manager.block')->createInstance('system_menu_block:menu-admin', $data);
$variables = array();
$variables['elements']['#block'] = $block;
+ $variables['elements']['#block_config'] = $block->getPlugin()->getConfig() + array(
+ 'id' => $block->get('plugin'),
+ 'region' => $block->get('region'),
+ 'module' => $block->get('module'),
+ );
$variables['elements']['#children'] = '';
// Test adding a class to the block content.
$variables['content_attributes']['class'][] = 'test-class';
template_preprocess_block($variables);
- $this->assertEqual($variables['theme_hook_suggestions'], array('block__footer', 'block__system', 'block__system_menu_block', 'block__system_menu_block__menu_admin'));
+ $this->assertEqual($variables['theme_hook_suggestions'], array('block__footer', 'block__system', 'block__system_menu_block', 'block__system_menu_block__menu_admin', 'block__machinename'));
$this->assertEqual($variables['content_attributes']['class'], array('test-class', 'content'), 'Default .content class added to block content_attributes_array');
}
+
}
diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php
index c607973..665e502 100644
--- a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php
+++ b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php
@@ -67,10 +67,8 @@ function setUp() {
*/
protected function removeDefaultBlocks() {
$default_theme = variable_get('theme_default', 'stark');
- $manager = $this->container->get('plugin.manager.block');
- $instances = config_get_storage_names_with_prefix('plugin.core.block.' . $default_theme);
- foreach ($instances as $plugin_id) {
- config($plugin_id)->delete();
+ foreach (entity_load_multiple_by_properties('block', array('theme' => $default_theme)) as $block) {
+ $block->delete();
}
}
@@ -82,8 +80,7 @@ public function testCustomBlock() {
$this->removeDefaultBlocks();
// Clear the block cache to load the Custom Block module's block definitions.
- $manager = $this->container->get('plugin.manager.block');
- $manager->clearCachedDefinitions();
+ $this->container->get('plugin.manager.block')->clearCachedDefinitions();
// Enable a second theme.
theme_enable(array('seven'));
@@ -110,21 +107,23 @@ public function testCustomBlock() {
$info = strtolower($this->randomName(8));
$custom_block['machine_name'] = $info;
$custom_block['info'] = $info;
- $custom_block['title'] = $this->randomName(8);
+ $custom_block['label'] = $this->randomName(8);
$custom_block['body[value]'] = $this->randomName(32);
$custom_block['region'] = $this->regions[0];
$this->drupalPost("admin/structure/block/list/block_plugin_ui:$default_theme/add/custom_blocks", $custom_block, t('Save block'));
- $plugin_id = "plugin.core.block.$default_theme.$info";
- $block = $manager->getInstance(array('config' => $plugin_id));
- $config = $block->getConfig();
+ $block = entity_load('block', $default_theme . '.' . $info);
// Confirm that the custom block has been created, and then query the created bid.
$this->assertText(t('The block configuration has been saved.'), 'Custom block successfully created.');
- // Check that block_block_view() returns the correct title and content.
- $data = $block->build();
- $format = $config['format'];
- $this->assertEqual(check_markup($custom_block['body[value]'], $format), render($data), 'BlockInterface::build() provides correct block content.');
+ // Check that entity_view() returns the correct title and content.
+ // @todo This assumes that a block's content can be rendered without its
+ // wrappers. If this is a reasonable expectation, it should be documented
+ // elsewhere.
+ $data = entity_view($block, 'content');
+ $definition = $block->getPlugin()->getDefinition();
+ $config = $definition['settings'];
+ $this->assertEqual(check_markup($custom_block['body[value]'], $config['format']), render($data), 'BlockInterface::build() provides correct block content.');
// Check whether the block can be moved to all available regions.
$custom_block['module'] = 'block';
@@ -134,7 +133,7 @@ public function testCustomBlock() {
// Verify presence of configure and delete links for custom block.
$this->drupalGet('admin/structure/block');
- $config_block_id = "admin/structure/block/manage/plugin.core.block.$default_theme.$info/$default_theme";
+ $config_block_id = "admin/structure/block/manage/$default_theme.$info";
$this->assertLinkByHref("$config_block_id/configure", 0, 'Custom block configure link found.');
$this->assertLinkByHref("$config_block_id/delete", 0, 'Custom block delete link found.');
@@ -146,9 +145,9 @@ public function testCustomBlock() {
// Delete the created custom block & verify that it's been deleted and no longer appearing on the page.
$this->clickLink(t('delete'));
$this->drupalPost("$config_block_id/delete", array(), t('Delete'));
- $this->assertRaw(t('The block %title has been removed.', array('%title' => $custom_block['title'])), 'Custom block successfully deleted.');
+ $this->assertRaw(t('The block %title has been removed.', array('%title' => $custom_block['label'])), 'Custom block successfully deleted.');
$this->drupalGet(NULL);
- $this->assertNoText(t($custom_block['title']), 'Custom block no longer appears on page.');
+ $this->assertNoText(t($custom_block['label']), 'Custom block no longer appears on page.');
}
/**
@@ -162,7 +161,7 @@ public function testCustomBlockFormat() {
$info = $this->randomName(8);
$custom_block['machine_name'] = $info;
$custom_block['info'] = $info;
- $custom_block['title'] = $this->randomName(8);
+ $custom_block['label'] = $this->randomName(8);
$custom_block['body[value]'] = 'Full HTML
';
$full_html_format = filter_format_load('full_html');
$custom_block['body[format]'] = $full_html_format->format;
@@ -170,7 +169,7 @@ public function testCustomBlockFormat() {
$this->drupalPost("admin/structure/block/list/block_plugin_ui:$default_theme/add/custom_blocks", $custom_block, t('Save block'));
// Set the created custom block to a specific region.
- $edit['blocks[0][region]'] = $this->regions[1];
+ $edit['blocks[' . $default_theme . '.' . $custom_block['machine_name'] . '][region]'] = $this->regions[1];
$this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
// Confirm that the custom block is being displayed using configured text format.
@@ -180,11 +179,10 @@ public function testCustomBlockFormat() {
// Confirm that a user without access to Full HTML can not see the body field,
// but can still submit the form without errors.
$block_admin = $this->drupalCreateUser(array('administer blocks'));
- $config_block_id = "admin/structure/block/manage/plugin.core.block.$default_theme.$info/$default_theme";
$this->drupalLogin($block_admin);
- $this->drupalGet("$config_block_id/configure");
+ $this->drupalGet("admin/structure/block/manage/$default_theme.$info/configure");
$this->assertFieldByXPath("//textarea[@name='body[value]' and @disabled='disabled']", t('This field has been disabled because you do not have sufficient permissions to edit it.'), 'Body field contains denied message');
- $this->drupalPost("$config_block_id/configure", array(), t('Save block'));
+ $this->drupalPost("admin/structure/block/manage/$default_theme.$info/configure", array(), t('Save block'));
$this->assertNoText(t('Ensure that each block description is unique.'));
// Confirm that the custom block is still being displayed using configured text format.
@@ -204,13 +202,13 @@ function testBlockVisibility() {
$edit = array(
'machine_name' => $this->randomName(8),
'region' => 'sidebar_first',
- 'title' => $title,
+ 'label' => $title,
);
// Set the block to be hidden on any user path, and to be shown only to
// authenticated users.
$edit['visibility[path][pages]'] = 'user*';
$edit['visibility[role][roles][' . DRUPAL_AUTHENTICATED_RID . ']'] = TRUE;
- $this->drupalPost('admin/structure/block/manage/' . $block_name . '/' . $default_theme, $edit, t('Save block'));
+ $this->drupalPost('admin/structure/block/add/' . $block_name . '/' . $default_theme, $edit, t('Save block'));
$this->assertText('The block configuration has been saved.', 'Block was saved');
$this->drupalGet('');
@@ -244,12 +242,12 @@ function testBlockVisibilityListedEmpty() {
$edit = array(
'machine_name' => $this->randomName(8),
'region' => 'sidebar_first',
- 'title' => $title,
+ 'label' => $title,
'visibility[path][visibility]' => BLOCK_VISIBILITY_LISTED,
);
// Set the block to be hidden on any user path, and to be shown only to
// authenticated users.
- $this->drupalPost('admin/structure/block/manage/' . $block_name . '/' . $default_theme, $edit, t('Save block'));
+ $this->drupalPost('admin/structure/block/add/' . $block_name . '/' . $default_theme, $edit, t('Save block'));
$this->assertText('The block configuration has been saved.', 'Block was saved');
$this->drupalGet('user');
@@ -272,20 +270,18 @@ function testBlock() {
// Select the 'Powered by Drupal' block to be configured and moved.
$block = array();
$block['id'] = 'system_powered_by_block';
- $block['title'] = $this->randomName(8);
+ $block['label'] = $this->randomName(8);
$block['machine_name'] = $this->randomName(8);
$block['theme'] = variable_get('theme_default', 'stark');
$block['region'] = 'header';
// Set block title to confirm that interface works and override any custom titles.
- $this->drupalPost('admin/structure/block/manage/' . $block['id'] . '/' . $block['theme'], array('title' => $block['title'], 'machine_name' => $block['machine_name'], 'region' => $block['region']), t('Save block'));
+ $this->drupalPost('admin/structure/block/add/' . $block['id'] . '/' . $block['theme'], array('label' => $block['label'], 'machine_name' => $block['machine_name'], 'region' => $block['region']), t('Save block'));
$this->assertText(t('The block configuration has been saved.'), 'Block title set.');
// Check to see if the block was created by checking its configuration.
- $block['config_id'] = 'plugin.core.block.' . $block['theme'] . '.' . $block['machine_name'];
- $instance = block_load($block['config_id']);
- $config = $instance->getConfig();
+ $instance = entity_load('block', $block['theme'] . '.' . $block['machine_name']);
- $this->assertEqual($config['subject'], $block['title'], 'Stored block title found.');
+ $this->assertEqual($instance->label(), $block['label'], 'Stored block title found.');
// Check whether the block can be moved to all available regions.
foreach ($this->regions as $region) {
@@ -294,7 +290,7 @@ function testBlock() {
// Set the block to the disabled region.
$edit = array();
- $edit['blocks[0][region]'] = -1;
+ $edit['blocks[' . $block['theme'] . '.' . $block['machine_name'] . '][region]'] = -1;
$this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
// Confirm that the block is now listed as disabled.
@@ -302,7 +298,7 @@ function testBlock() {
// Confirm that the block instance title and markup are not displayed.
$this->drupalGet('node');
- $this->assertNoText(t($block['title']));
+ $this->assertNoText(t($block['label']));
// Check for if the machine name
// is my_block_instance_name.
$xpath = $this->buildXPathQuery('//div[@id=:id]/*', array(':id' => 'block-' . strtr(strtolower($block['machine_name']), '-', '_')));
@@ -323,8 +319,9 @@ function testBlock() {
*/
function moveBlockToRegion(array $block, $region) {
// Set the created block to a specific region.
+ $block += array('theme' => variable_get('theme_default', 'stark'));
$edit = array();
- $edit['blocks[0][region]'] = $region;
+ $edit['blocks[' . $block['theme'] . '.' . $block['machine_name'] . '][region]'] = $region;
$this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
// Confirm that the block was moved to the proper region.
@@ -332,7 +329,7 @@ function moveBlockToRegion(array $block, $region) {
// Confirm that the block is being displayed.
$this->drupalGet('');
- $this->assertText(t($block['title']), 'Block successfully being displayed on the page.');
+ $this->assertText(t($block['label']), 'Block successfully being displayed on the page.');
// Confirm that the custom block was found at the proper region.
$xpath = $this->buildXPathQuery('//div[@class=:region-class]//div[@id=:block-id]/*', array(
@@ -350,34 +347,30 @@ function testBlockRehash() {
$this->assertTrue(module_exists('block_test'), 'Test block module enabled.');
// Clear the block cache to load the block_test module's block definitions.
- $manager = $this->container->get('plugin.manager.block');
- $manager->clearCachedDefinitions();
+ $this->container->get('plugin.manager.block')->clearCachedDefinitions();
// Add a test block.
- $plugin = $manager->getDefinition('test_cache');
$block = array();
$block['id'] = 'test_cache';
$block['machine_name'] = $this->randomName(8);
$block['theme'] = variable_get('theme_default', 'stark');
$block['region'] = 'header';
- $this->drupalPost('admin/structure/block/manage/' . $block['id'] . '/' . $block['theme'], array('machine_name' => $block['machine_name'], 'region' => $block['region']), t('Save block'));
+ $block = $this->drupalPlaceBlock('test_cache', array('region' => 'header'));
// Our test block's caching should default to DRUPAL_CACHE_PER_ROLE.
- $block['config_id'] = 'plugin.core.block.' . $block['theme'] . '.' . $block['machine_name'];
- $instance = block_load($block['config_id']);
- $config = $instance->getConfig();
- $this->assertEqual($config['cache'], DRUPAL_CACHE_PER_ROLE, 'Test block cache mode defaults to DRUPAL_CACHE_PER_ROLE.');
+ $settings = $block->get('settings');
+ $this->assertEqual($settings['cache'], DRUPAL_CACHE_PER_ROLE, 'Test block cache mode defaults to DRUPAL_CACHE_PER_ROLE.');
// Disable caching for this block.
- $block_config = config($block['config_id']);
- $block_config->set('cache', DRUPAL_NO_CACHE);
- $block_config->save();
+ $settings['cache'] = DRUPAL_NO_CACHE;
+ $block->set('settings', $settings);
+ $block->save();
// Flushing all caches should call _block_rehash().
$this->resetAll();
// Verify that block is updated with the new caching mode.
- $instance = block_load($block['config_id']);
- $config = $instance->getConfig();
- $this->assertEqual($config['cache'], DRUPAL_NO_CACHE, "Test block's database entry updated to DRUPAL_NO_CACHE.");
+ $block = entity_load('block', $block->id());
+ $settings = $block->get('settings');
+ $this->assertEqual($settings['cache'], DRUPAL_NO_CACHE, "Test block's database entry updated to DRUPAL_NO_CACHE.");
}
/**
@@ -399,7 +392,7 @@ function testBlockModuleDisable() {
}
$this->drupalGet('');
foreach ($regions as $region) {
- $this->assertText($blocks[$region]['subject']);
+ $this->assertText($blocks[$region]->label());
}
// Disable the block test module and refresh the definitions cache.
@@ -415,7 +408,7 @@ function testBlockModuleDisable() {
// Ensure that the disabled module's block instance is not listed.
foreach ($regions as $region) {
- $this->assertNoText($blocks[$region]['subject']);
+ $this->assertNoText($blocks[$region]->label());
}
// Ensure that the disabled module's block plugin is no longer available.
@@ -426,7 +419,7 @@ function testBlockModuleDisable() {
$this->drupalGet('');
$this->assertResponse(200);
foreach ($regions as $region) {
- $this->assertNoText($blocks[$region]['subject']);
+ $this->assertNoText($blocks[$region]->label());
}
// Confirm that a different block instance can still be enabled by
@@ -434,16 +427,16 @@ function testBlockModuleDisable() {
// Emulate a POST submission rather than using drupalPlaceBlock() to ensure
// that the form still functions as expected.
$edit = array(
- 'title' => $this->randomName(8),
+ 'label' => $this->randomName(8),
'machine_name' => $this->randomName(8),
'region' => 'sidebar_first',
);
- $this->drupalPost('admin/structure/block/manage/system_powered_by_block/stark', $edit, t('Save block'));
+ $this->drupalPost('admin/structure/block/add/system_powered_by_block/stark', $edit, t('Save block'));
$this->assertText(t('The block configuration has been saved.'));
- $this->assertText($edit['title']);
+ $this->assertText($edit['label']);
// Update the weight of a block.
- $edit = array('blocks[0][weight]' => -1);
+ $edit = array('blocks[stark.' . $edit['machine_name'] . '][weight]' => -1);
$this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
$this->assertText(t('The block settings have been updated.'));
@@ -455,7 +448,7 @@ function testBlockModuleDisable() {
// Reload the admin page and confirm the block can again be configured.
$this->drupalGet('admin/structure/block');
foreach ($regions as $region) {
- $this->assertLinkByHref(url('admin/structure/block/manage/' . $blocks[$region]['config_id'] . '/stark/config'));
+ $this->assertLinkByHref(url('admin/structure/block/manage/' . $blocks[$region]->id()));
}
// Confirm that the blocks are again displayed on the front page in the
@@ -463,14 +456,14 @@ function testBlockModuleDisable() {
$this->drupalGet('');
foreach ($regions as $region) {
// @todo Use a proper method for this.
- $name_pieces = explode('.', $blocks[$region]['config_id']);
+ $name_pieces = explode('.', $blocks[$region]->id());
$machine_name = array_pop($name_pieces);
$xpath = $this->buildXPathQuery('//div[@class=:region-class]//div[@id=:block-id]/*', array(
':region-class' => 'region region-' . drupal_html_class($region),
':block-id' => 'block-' . strtr(strtolower($machine_name), '-', '_'),
));
$this->assertFieldByXPath($xpath, NULL, format_string('Block %name found in the %region region.', array(
- '%name' => $blocks[$region]['subject'],
+ '%name' => $blocks[$region]->label(),
'%region' => $region,
)));
}
diff --git a/core/modules/block/tests/config/plugin.core.block.stark.test_block.yml b/core/modules/block/tests/config/plugin.core.block.stark.test_block.yml
new file mode 100644
index 0000000..7428765
--- /dev/null
+++ b/core/modules/block/tests/config/plugin.core.block.stark.test_block.yml
@@ -0,0 +1,11 @@
+id: stark.test_block
+label: ''
+region: '-1'
+weight: ''
+module: block_test
+status: '1'
+visibility: { }
+plugin: test_html_id
+settings:
+ cache: '1'
+ subject: 'Test block html id'
diff --git a/core/modules/block/tests/lib/Drupal/block_test/Plugin/block/block/TestCacheBlock.php b/core/modules/block/tests/lib/Drupal/block_test/Plugin/block/block/TestCacheBlock.php
index aeb7709..5f7b980 100644
--- a/core/modules/block/tests/lib/Drupal/block_test/Plugin/block/block/TestCacheBlock.php
+++ b/core/modules/block/tests/lib/Drupal/block_test/Plugin/block/block/TestCacheBlock.php
@@ -10,6 +10,7 @@
use Drupal\block\BlockBase;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
+use Drupal\block\Plugin\Core\Entity\Block;
/**
* Provides a block to test caching.
@@ -36,7 +37,7 @@ public function blockSettings() {
/**
* Implements \Drupal\block\BlockBase::blockBuild().
*/
- public function blockBuild() {
+ public function blockBuild(Block $entity) {
return array(
'#children' => state()->get('block_test.content'),
);
diff --git a/core/modules/book/lib/Drupal/book/Plugin/block/block/BookNavigationBlock.php b/core/modules/book/lib/Drupal/book/Plugin/block/block/BookNavigationBlock.php
index c1823e1..1f43782 100644
--- a/core/modules/book/lib/Drupal/book/Plugin/block/block/BookNavigationBlock.php
+++ b/core/modules/book/lib/Drupal/book/Plugin/block/block/BookNavigationBlock.php
@@ -10,6 +10,7 @@
use Drupal\block\BlockBase;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
+use Drupal\block\Plugin\Core\Entity\Block;
/**
* Provides a 'Book navigation' block.
@@ -61,7 +62,7 @@ public function blockSubmit($form, &$form_state) {
/**
* Implements \Drupal\block\BlockBase::blockBuild().
*/
- public function blockBuild() {
+ public function blockBuild(Block $entity) {
$current_bid = 0;
if ($node = menu_get_object()) {
$current_bid = empty($node->book['bid']) ? 0 : $node->book['bid'];
diff --git a/core/modules/book/lib/Drupal/book/Tests/BookTest.php b/core/modules/book/lib/Drupal/book/Tests/BookTest.php
index 16c8ae3..0a1ffcf 100644
--- a/core/modules/book/lib/Drupal/book/Tests/BookTest.php
+++ b/core/modules/book/lib/Drupal/book/Tests/BookTest.php
@@ -321,7 +321,7 @@ function testBookNavigationBlock() {
// Test correct display of the block.
$nodes = $this->createBook();
$this->drupalGet('
');
- $this->assertText($block['subject'], 'Book navigation block is displayed.');
+ $this->assertText($block->label(), 'Book navigation block is displayed.');
$this->assertText($this->book->label(), format_string('Link to book root (@title) is displayed.', array('@title' => $nodes[0]->label())));
$this->assertNoText($nodes[0]->label(), 'No links to individual book pages are displayed.');
}
@@ -331,7 +331,7 @@ function testBookNavigationBlock() {
*/
function testNavigationBlockOnAccessModuleEnabled() {
$this->drupalLogin($this->admin_user);
- $block = $this->drupalPlaceBlock('book_navigation', array('book_block_mode' => 'book pages'));
+ $block = $this->drupalPlaceBlock('book_navigation', array(), array('block_mode' => 'book pages'));
// Give anonymous users the permission 'node test view'.
$edit = array();
@@ -345,12 +345,16 @@ function testNavigationBlockOnAccessModuleEnabled() {
// Test correct display of the block to registered users.
$this->drupalLogin($this->web_user);
$this->drupalGet('node/' . $this->book->nid);
- $this->assertText($block['subject'], 'Book navigation block is displayed to registered users.');
+ $this->assertText($block->label(), 'Book navigation block is displayed to registered users.');
$this->drupalLogout();
// Test correct display of the block to anonymous users.
$this->drupalGet('node/' . $this->book->nid);
- $this->assertText($block['subject'], 'Book navigation block is displayed to anonymous users.');
+ $this->assertText($block->label(), 'Book navigation block is displayed to anonymous users.');
+
+ // Test the 'book pages' block_mode setting.
+ $this->drupalGet('');
+ $this->assertNoText($block->label(), 'Book navigation block is not shown on non-book pages.');
}
/**
diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/block/block/RecentCommentsBlock.php b/core/modules/comment/lib/Drupal/comment/Plugin/block/block/RecentCommentsBlock.php
index d5c3d7b..77114fe 100644
--- a/core/modules/comment/lib/Drupal/comment/Plugin/block/block/RecentCommentsBlock.php
+++ b/core/modules/comment/lib/Drupal/comment/Plugin/block/block/RecentCommentsBlock.php
@@ -10,6 +10,7 @@
use Drupal\block\BlockBase;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
+use Drupal\block\Plugin\Core\Entity\Block;
/**
* Provides a 'Recent comments' block.
@@ -61,7 +62,7 @@ public function blockSubmit($form, &$form_state) {
/**
* Implements \Drupal\block\BlockBase::blockBuild().
*/
- public function blockBuild() {
+ public function blockBuild(Block $entity) {
return array(
'#theme' => 'comment_block',
'#number' => $this->configuration['block_count'],
diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentBlockTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentBlockTest.php
index 8b4e842..901d325 100644
--- a/core/modules/comment/lib/Drupal/comment/Tests/CommentBlockTest.php
+++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentBlockTest.php
@@ -46,7 +46,7 @@ public static function getInfo() {
*/
function testRecentCommentBlock() {
$this->drupalLogin($this->admin_user);
- $block = $this->drupalPlaceBlock('recent_comments', array('block_count' => 2));
+ $block = $this->drupalPlaceBlock('recent_comments', array(), array('block_count' => 2));
// Add some test comments, one without a subject.
$comment1 = $this->postComment($this->node, $this->randomName(), $this->randomName());
@@ -61,14 +61,15 @@ function testRecentCommentBlock() {
// posting a node from a node form.
cache_invalidate_tags(array('content' => TRUE));
$this->drupalGet('');
- $this->assertNoText($block['subject'], 'Block was not found.');
+ $label = $block->label();
+ $this->assertNoText($label, 'Block was not found.');
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access comments'));
// Test that a user with the 'access comments' permission can see the
// block.
$this->drupalLogin($this->web_user);
$this->drupalGet('');
- $this->assertText($block['subject'], 'Block was found.');
+ $this->assertText($label, 'Block was found.');
// Test the only the 2 latest comments are shown and in the proper order.
$this->assertNoText($comment1->subject->value, 'Comment not found in block.');
@@ -77,15 +78,8 @@ function testRecentCommentBlock() {
$this->assertTrue(strpos($this->drupalGetContent(), $comment3->comment_body->value) < strpos($this->drupalGetContent(), $comment2->subject->value), 'Comments were ordered correctly in block.');
// Set the number of recent comments to show to 10.
- $this->drupalLogout();
- $this->drupalLogin($this->admin_user);
- $edit = array(
- 'block_count' => 10,
- );
- $current_theme = variable_get('theme_default', 'stark');
-
- $this->drupalPost('admin/structure/block/manage/' . $block['config_id'] . '/' . variable_get('theme_default', 'stark') . '/configure', $edit, t('Save block'));
- $this->assertText(t('The block configuration has been saved.'), 'Block saved.');
+ $block->set('settings', array('block_count' => 10));
+ $block->save();
// Post an additional comment.
$comment4 = $this->postComment($this->node, $this->randomName(), $this->randomName());
diff --git a/core/modules/forum/lib/Drupal/forum/Plugin/block/block/ActiveTopicsBlock.php b/core/modules/forum/lib/Drupal/forum/Plugin/block/block/ActiveTopicsBlock.php
index afa7117..7ac7010 100644
--- a/core/modules/forum/lib/Drupal/forum/Plugin/block/block/ActiveTopicsBlock.php
+++ b/core/modules/forum/lib/Drupal/forum/Plugin/block/block/ActiveTopicsBlock.php
@@ -9,6 +9,7 @@
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
+use Drupal\block\Plugin\Core\Entity\Block;
/**
* Provides an 'Active forum topics' block.
@@ -24,7 +25,7 @@ class ActiveTopicsBlock extends ForumBlockBase {
/**
* Implements \Drupal\block\BlockBase::blockBuild().
*/
- public function blockBuild() {
+ public function blockBuild(Block $entity) {
$query = db_select('forum_index', 'f')
->fields('f')
->addTag('node_access')
diff --git a/core/modules/forum/lib/Drupal/forum/Plugin/block/block/NewTopicsBlock.php b/core/modules/forum/lib/Drupal/forum/Plugin/block/block/NewTopicsBlock.php
index 083469c..2cfcb8b 100644
--- a/core/modules/forum/lib/Drupal/forum/Plugin/block/block/NewTopicsBlock.php
+++ b/core/modules/forum/lib/Drupal/forum/Plugin/block/block/NewTopicsBlock.php
@@ -9,6 +9,7 @@
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
+use Drupal\block\Plugin\Core\Entity\Block;
/**
* Provides a 'New forum topics' block.
@@ -24,7 +25,7 @@ class NewTopicsBlock extends ForumBlockBase {
/**
* Implements \Drupal\block\BlockBase::blockBuild().
*/
- public function blockBuild() {
+ public function blockBuild(Block $entity) {
$query = db_select('forum_index', 'f')
->fields('f')
->addTag('node_access')
diff --git a/core/modules/forum/lib/Drupal/forum/Tests/ForumBlockTest.php b/core/modules/forum/lib/Drupal/forum/Tests/ForumBlockTest.php
index 7f5405d..9fe5acb 100644
--- a/core/modules/forum/lib/Drupal/forum/Tests/ForumBlockTest.php
+++ b/core/modules/forum/lib/Drupal/forum/Tests/ForumBlockTest.php
@@ -59,7 +59,7 @@ public function testNewForumTopicsBlock() {
// Enable the new forum topics block.
$block = $this->drupalPlaceBlock('forum_new_block');
- $this->assertText(t('The block configuration has been saved.'), '"New forum topics" block was enabled');
+ $this->drupalGet('');
$this->assertLink(t('More'), 0, 'New forum topics block has a "more"-link.');
$this->assertLinkByHref('forum', 0, 'New forum topics block has a "more"-link.');
@@ -70,9 +70,8 @@ public function testNewForumTopicsBlock() {
}
// Configure the new forum topics block to only show 2 topics.
- $config = config($block['config_id']);
- $config->set('block_count', 2);
- $config->save();
+ $block->set('settings', array('block_count' => 2));
+ $block->save();
$this->drupalGet('');
// We expect only the 2 most recent forum topics to appear in the "New forum
@@ -113,6 +112,7 @@ public function testActiveForumTopicsBlock() {
// Enable the block.
$block = $this->drupalPlaceBlock('forum_active_block');
+ $this->drupalGet('');
$this->assertLink(t('More'), 0, 'Active forum topics block has a "more"-link.');
$this->assertLinkByHref('forum', 0, 'Active forum topics block has a "more"-link.');
@@ -129,9 +129,8 @@ public function testActiveForumTopicsBlock() {
}
// Configure the active forum block to only show 2 topics.
- $config = config($block['config_id']);
- $config->set('block_count', 2);
- $config->save();
+ $block->set('settings', array('block_count' => 2));
+ $block->save();
$this->drupalGet('');
diff --git a/core/modules/language/language.module b/core/modules/language/language.module
index c2356be..c8f3b7b 100644
--- a/core/modules/language/language.module
+++ b/core/modules/language/language.module
@@ -47,7 +47,8 @@ function language_help($path, $arg) {
return $output;
- case 'admin/structure/block/manage/%/%':
+ case 'admin/structure/block/manage/%':
+ case 'admin/structure/block/add/%/%':
if ($arg[4] == 'language' && $arg[5] == 'language_interface') {
return '' . t('With multiple languages enabled, registered users can select their preferred language and authors can assign a specific language to content.') . '
';
}
diff --git a/core/modules/language/lib/Drupal/language/Plugin/block/block/LanguageBlock.php b/core/modules/language/lib/Drupal/language/Plugin/block/block/LanguageBlock.php
index 74fb83a..89d6562 100644
--- a/core/modules/language/lib/Drupal/language/Plugin/block/block/LanguageBlock.php
+++ b/core/modules/language/lib/Drupal/language/Plugin/block/block/LanguageBlock.php
@@ -10,6 +10,7 @@
use Drupal\block\BlockBase;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
+use Drupal\block\Plugin\Core\Entity\Block;
/**
* Provides a 'Language switcher' block.
@@ -33,13 +34,14 @@ function blockAccess() {
/**
* Implements \Drupal\block\BlockBase::blockBuild().
*/
- public function blockBuild() {
+ public function blockBuild(Block $entity) {
+ $build = array();
$path = drupal_is_front_page() ? '' : current_path();
list($plugin_id, $type) = explode(':', $this->getPluginId());
$links = language_negotiation_get_switch_links($type, $path);
if (isset($links->links)) {
- return array(
+ $build = array(
'#theme' => 'links__language_block',
'#links' => $links->links,
'#attributes' => array(
@@ -49,6 +51,7 @@ public function blockBuild() {
),
);
}
+ return $build;
}
}
diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageSwitchingTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageSwitchingTest.php
index 8effdfe..ac834d1 100644
--- a/core/modules/language/lib/Drupal/language/Tests/LanguageSwitchingTest.php
+++ b/core/modules/language/lib/Drupal/language/Tests/LanguageSwitchingTest.php
@@ -56,7 +56,7 @@ function testLanguageBlock() {
// Assert that the language switching block is displayed on the frontpage.
$this->drupalGet('');
- $this->assertText($block['subject'], 'Language switcher block found.');
+ $this->assertText($block->label(), 'Language switcher block found.');
// Assert that only the current language is marked as active.
list($language_switcher) = $this->xpath('//div[@id=:id]/div[@class="content"]', array(':id' => 'block-test-language-block'));
diff --git a/core/modules/menu/lib/Drupal/menu/Plugin/block/block/MenuBlock.php b/core/modules/menu/lib/Drupal/menu/Plugin/block/block/MenuBlock.php
index 7134dc50..2924bee 100644
--- a/core/modules/menu/lib/Drupal/menu/Plugin/block/block/MenuBlock.php
+++ b/core/modules/menu/lib/Drupal/menu/Plugin/block/block/MenuBlock.php
@@ -10,6 +10,7 @@
use Drupal\system\Plugin\block\block\SystemMenuBlock;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
+use Drupal\block\Plugin\Core\Entity\Block;
/**
* Provides a generic Menu block.
@@ -26,7 +27,7 @@ class MenuBlock extends SystemMenuBlock {
/**
* Implements \Drupal\block\BlockBase::blockBuild().
*/
- public function blockBuild() {
+ public function blockBuild(Block $entity) {
list($plugin, $menu) = explode(':', $this->getPluginId());
return menu_tree($menu);
}
diff --git a/core/modules/menu/menu.module b/core/modules/menu/menu.module
index 3d4a360..1b1aee5 100644
--- a/core/modules/menu/menu.module
+++ b/core/modules/menu/menu.module
@@ -12,6 +12,7 @@
*/
use Drupal\node\Plugin\Core\Entity\Node;
+use Drupal\block\Plugin\Core\Entity\Block;
use Drupal\system\Plugin\Core\Entity\Menu;
use Drupal\system\Plugin\block\block\SystemMenuBlock;
use Symfony\Component\HttpFoundation\JsonResponse;
@@ -292,6 +293,7 @@ function menu_menu_predelete(Menu $menu) {
*/
function menu_menu_delete(Menu $menu) {
menu_cache_clear_all();
+
// Invalidate the block cache to update menu-based derivatives.
if (module_exists('block')) {
drupal_container()->get('plugin.manager.block')->clearCachedDefinitions();
@@ -431,9 +433,9 @@ function menu_reset_item($link) {
/**
* Implements hook_block_view_alter().
*/
-function menu_block_view_alter(&$build, $block) {
+function menu_block_view_alter(array &$build, Block $block) {
// Add contextual links for system menu blocks.
- if ($block instanceof SystemMenuBlock) {
+ if ($block->getPlugin() instanceof SystemMenuBlock) {
foreach (element_children($build) as $key) {
$build['#contextual_links']['menu'] = array('admin/structure/menu/manage', array($build[$key]['#original_link']['menu_name']));
}
diff --git a/core/modules/node/lib/Drupal/node/Plugin/block/block/RecentContentBlock.php b/core/modules/node/lib/Drupal/node/Plugin/block/block/RecentContentBlock.php
index cb05c5c..d9abc2d 100644
--- a/core/modules/node/lib/Drupal/node/Plugin/block/block/RecentContentBlock.php
+++ b/core/modules/node/lib/Drupal/node/Plugin/block/block/RecentContentBlock.php
@@ -10,6 +10,7 @@
use Drupal\block\BlockBase;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
+use Drupal\block\Plugin\Core\Entity\Block;
/**
* Provides a 'Recent content' block.
@@ -61,7 +62,7 @@ public function blockSubmit($form, &$form_state) {
/**
* Implements \Drupal\block\BlockBase::blockBuild().
*/
- public function blockBuild() {
+ public function blockBuild(Block $entity) {
if ($nodes = node_get_recent($this->configuration['block_count'])) {
return array(
'#theme' => 'node_recent_block',
diff --git a/core/modules/node/lib/Drupal/node/Plugin/block/block/SyndicateBlock.php b/core/modules/node/lib/Drupal/node/Plugin/block/block/SyndicateBlock.php
index 5c83e27..b83d9f4 100644
--- a/core/modules/node/lib/Drupal/node/Plugin/block/block/SyndicateBlock.php
+++ b/core/modules/node/lib/Drupal/node/Plugin/block/block/SyndicateBlock.php
@@ -10,6 +10,7 @@
use Drupal\block\BlockBase;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
+use Drupal\block\Plugin\Core\Entity\Block;
/**
* Provides a 'Syndicate' block that links to the site's RSS feed.
@@ -41,7 +42,7 @@ public function blockAccess() {
/**
* Implements \Drupal\block\BlockBase::blockBuild().
*/
- public function blockBuild() {
+ public function blockBuild(Block $entity) {
return array(
'#theme' => 'feed_icon',
'#url' => 'rss.xml',
diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeBlockFunctionalTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeBlockFunctionalTest.php
index b5d5205..3beb969 100644
--- a/core/modules/node/lib/Drupal/node/Tests/NodeBlockFunctionalTest.php
+++ b/core/modules/node/lib/Drupal/node/Tests/NodeBlockFunctionalTest.php
@@ -61,7 +61,7 @@ public function testRecentNodeBlock() {
));
// Enable the recent content block with two items.
- $block = $this->drupalPlaceBlock('node_recent_block', array('machine_name' => 'test_block', 'block_count' => 2));
+ $block = $this->drupalPlaceBlock('node_recent_block', array('machine_name' => 'test_block'), array('block_count' => 2));
// Test that block is not visible without nodes.
$this->drupalGet('');
@@ -91,7 +91,7 @@ public function testRecentNodeBlock() {
// see the block.
$this->drupalLogout();
$this->drupalGet('');
- $this->assertNoText($block['subject'], 'Block was not found.');
+ $this->assertNoText($block->label(), 'Block was not found.');
// Test that only the 2 latest nodes are shown.
$this->drupalLogin($this->webUser);
@@ -106,9 +106,8 @@ public function testRecentNodeBlock() {
$this->drupalLogin($this->adminUser);
// Set the number of recent nodes to show to 10.
- $config = config($block['config_id']);
- $config->set('block_count', 10);
- $config->save();
+ $block->set('settings', array('block_count' => 10));
+ $block->save();
// Post an additional node.
$node4 = $this->drupalCreateNode($default_settings);
@@ -125,24 +124,30 @@ public function testRecentNodeBlock() {
// Enable the "Powered by Drupal" block only on article nodes.
$block = $this->drupalPlaceBlock('system_powered_by_block', array(
- 'visibility[node_type][types][article]' => TRUE,
- ));
- $config = config($block['config_id']);
- $node_type_visibility = $config->get('visibility.node_type.types.article');
- $this->assertEqual($node_type_visibility, 'article', 'Visibility settings were saved to configuration');
+ 'visibility' => array(
+ 'node_type' => array(
+ 'types' => array(
+ 'article' => 'article',
+ ),
+ ),
+ ),
+ ));
+ $visibility = $block->get('visibility');
+ $this->assertTrue(isset($visibility['node_type']['types']['article']), 'Visibility settings were saved to configuration');
// Create a page node.
$node5 = $this->drupalCreateNode(array('uid' => $this->adminUser->uid, 'type' => 'page'));
// Verify visibility rules.
$this->drupalGet('');
- $this->assertNoText($block['subject'], 'Block was not displayed on the front page.');
+ $label = $block->label();
+ $this->assertNoText($label, 'Block was not displayed on the front page.');
$this->drupalGet('node/add/article');
- $this->assertText($block['subject'], 'Block was displayed on the node/add/article page.');
+ $this->assertText($label, 'Block was displayed on the node/add/article page.');
$this->drupalGet('node/' . $node1->nid);
- $this->assertText($block['subject'], 'Block was displayed on the node/N when node is of type article.');
+ $this->assertText($label, 'Block was displayed on the node/N when node is of type article.');
$this->drupalGet('node/' . $node5->nid);
- $this->assertNoText($block['subject'], 'Block was not displayed on nodes of type page.');
+ $this->assertNoText($label, 'Block was not displayed on nodes of type page.');
}
}
diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeSyndicateBlockTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeSyndicateBlockTest.php
index 4e5a209..887b7ea 100644
--- a/core/modules/node/lib/Drupal/node/Tests/NodeSyndicateBlockTest.php
+++ b/core/modules/node/lib/Drupal/node/Tests/NodeSyndicateBlockTest.php
@@ -41,6 +41,7 @@ function setUp() {
public function testSyndicateBlock() {
// Place the "Syndicate" block and confirm that it is rendered.
$this->drupalPlaceBlock('node_syndicate_block', array('machine_name' => 'test_syndicate_block'));
+ $this->drupalGet('');
$this->assertFieldByXPath('//div[@id="block-test-syndicate-block"]/*', NULL, 'Syndicate block found.');
}
diff --git a/core/modules/node/node.module b/core/modules/node/node.module
index e51c53f..e5947c5 100644
--- a/core/modules/node/node.module
+++ b/core/modules/node/node.module
@@ -1986,14 +1986,13 @@ function theme_node_recent_content($variables) {
}
/**
- * Implements hook_form_FORM_ID_alter() for block_admin_configure().
+ * Implements hook_form_FORM_ID_alter() for block_form().
*
* Adds node-type specific visibility options to block configuration form.
- *
- * @see node_form_block_admin_configure_submit()
*/
-function node_form_block_admin_configure_alter(&$form, &$form_state) {
- $config = $form['#instance']->getConfig();
+function node_form_block_form_alter(&$form, &$form_state) {
+ $block = $form_state['entity'];
+ $visibility = $block->get('visibility');
$form['visibility']['node_type'] = array(
'#type' => 'details',
'#title' => t('Content types'),
@@ -2005,7 +2004,7 @@ function node_form_block_admin_configure_alter(&$form, &$form_state) {
$form['visibility']['node_type']['types'] = array(
'#type' => 'checkboxes',
'#title' => t('Show block for specific content types'),
- '#default_value' => !empty($config['visibility']['node_type']['types']) ? $config['visibility']['node_type']['types'] : array(),
+ '#default_value' => !empty($visibility['node_type']['types']) ? $visibility['node_type']['types'] : array(),
'#options' => node_type_get_names(),
'#description' => t('Show this block only on pages that display content of the given type(s). If you select no types, there will be no type-specific limitation.'),
);
@@ -2018,9 +2017,8 @@ function node_form_block_admin_configure_alter(&$form, &$form_state) {
* if the visibility conditions are not met.
*/
function node_block_access($block) {
- $configuration = $block->getConfig();
- if (!empty($configuration['visibility'])) {
- $visibility = $configuration['visibility'];
+ $visibility = $block->get('visibility');
+ if (!empty($visibility)) {
$allowed_types = array();
$node = menu_get_object();
$node_types = node_type_get_types();
diff --git a/core/modules/overlay/overlay.module b/core/modules/overlay/overlay.module
index 54eaf18..632d270 100644
--- a/core/modules/overlay/overlay.module
+++ b/core/modules/overlay/overlay.module
@@ -477,8 +477,7 @@ function overlay_block_access($block) {
// reason for duplicating effort here is performance; we do not even want
// these blocks to be built if they are not going to be displayed.
if ($regions_to_render = overlay_get_regions_to_render()) {
- $config = $block->getConfig();
- if (!in_array($config['region'], $regions_to_render)) {
+ if (!in_array($block->get('region'), $regions_to_render)) {
return FALSE;
}
}
diff --git a/core/modules/poll/lib/Drupal/poll/Plugin/block/block/PollRecentBlock.php b/core/modules/poll/lib/Drupal/poll/Plugin/block/block/PollRecentBlock.php
index b597741..5b96e3b 100644
--- a/core/modules/poll/lib/Drupal/poll/Plugin/block/block/PollRecentBlock.php
+++ b/core/modules/poll/lib/Drupal/poll/Plugin/block/block/PollRecentBlock.php
@@ -10,6 +10,7 @@
use Drupal\block\BlockBase;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
+use Drupal\block\Plugin\Core\Entity\Block;
/**
* Provides a 'Most recent poll' block.
@@ -67,7 +68,7 @@ public function blockAccess() {
/**
* Implements \Drupal\block\BlockBase::blockBuild().
*/
- public function blockBuild() {
+ public function blockBuild(Block $entity) {
$poll = node_load($this->record);
if ($poll->nid) {
$poll = poll_block_latest_poll_view($poll);
diff --git a/core/modules/search/lib/Drupal/search/Plugin/block/block/SearchBlock.php b/core/modules/search/lib/Drupal/search/Plugin/block/block/SearchBlock.php
index d9bdb7c..4cdc83f 100644
--- a/core/modules/search/lib/Drupal/search/Plugin/block/block/SearchBlock.php
+++ b/core/modules/search/lib/Drupal/search/Plugin/block/block/SearchBlock.php
@@ -10,6 +10,7 @@
use Drupal\block\BlockBase;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
+use Drupal\block\Plugin\Core\Entity\Block;
/**
* Provides a 'Search form' block.
@@ -32,7 +33,7 @@ public function blockAccess() {
/**
* Implements \Drupal\block\BlockBase::blockBuild().
*/
- public function blockBuild() {
+ public function blockBuild(Block $entity) {
return array(drupal_get_form('search_block_form'));
}
diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchBlockTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchBlockTest.php
index b358ded..f3b4101 100644
--- a/core/modules/search/lib/Drupal/search/Tests/SearchBlockTest.php
+++ b/core/modules/search/lib/Drupal/search/Tests/SearchBlockTest.php
@@ -40,7 +40,9 @@ function setUp() {
*/
protected function testSearchFormBlock() {
$block = $this->drupalPlaceBlock('search_form_block');
- $this->assertText($block['subject'], 'Block title was found.');
+
+ $this->drupalGet('');
+ $this->assertText($block->label(), 'Block title was found.');
// Test a normal search via the block form, from the front page.
$terms = array('search_block_form' => 'test');
@@ -54,9 +56,9 @@ protected function testSearchFormBlock() {
$this->assertResponse(200);
$this->assertText('Your search yielded no results');
- $config = config($block['config_id']);
- $config->set('visibility.path.pages', 'search');
- $config->save();
+ $visibility = $block->get('visibility');
+ $visibility['path']['pages'] = 'search';
+ $block->set('visibility', $visibility);
$this->drupalPost('node', $terms, t('Search'));
$this->assertText('Your search yielded no results');
diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Plugin/block/block/ShortcutsBlock.php b/core/modules/shortcut/lib/Drupal/shortcut/Plugin/block/block/ShortcutsBlock.php
index d236a19..818650b 100644
--- a/core/modules/shortcut/lib/Drupal/shortcut/Plugin/block/block/ShortcutsBlock.php
+++ b/core/modules/shortcut/lib/Drupal/shortcut/Plugin/block/block/ShortcutsBlock.php
@@ -10,6 +10,7 @@
use Drupal\block\BlockBase;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
+use Drupal\block\Plugin\Core\Entity\Block;
/**
* Provides a 'Shortcut' block.
@@ -25,7 +26,7 @@ class ShortcutsBlock extends BlockBase {
/**
* Implements \Drupal\block\BlockBase::blockBuild().
*/
- public function blockBuild() {
+ public function blockBuild(Block $entity) {
return array(
shortcut_renderable_links(shortcut_current_displayed_set()),
);
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
index 85aba85..5f2a3ee 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
@@ -347,69 +347,43 @@ protected function drupalCreateContentType($settings = array()) {
*
* @param string $plugin_id
* The plugin ID of the block type for this block instance.
- * @param array $settings
- * (optional) An associative array of settings for the block instance.
- * Override the defaults by specifying the key and value in the array, for
+ * @param array $values
+ * (optional) An associative array of values for the block entity.
+ * Override the defaults by specifying the key and value in the array, for
* example:
* @code
* $this->drupalPlaceBlock('system_powered_by_block', array(
- * 'title' => t('Hello, world!'),
+ * 'label' => t('Hello, world!'),
* ));
* @endcode
* The following defaults are provided:
- * - title: Random string.
+ * - label: Random string.
* - machine_name: Random string.
* - region: 'sidebar_first'.
- * @param string $theme
- * (optional) The theme for which to add a block instance. Defaults to the
- * default theme.
+ * - theme: The default theme.
+ * @param array $settings
+ * (optional) An associative array of plugin-specific settings.
*
- * @return array|false
- * The block instance configuration from BlockBase::getConfig(), or FALSE
- * on failure.
+ * @return \Drupal\block\Plugin\Core\Entity\Block
+ * The block entity.
*
* @todo
- * Create the block programmatically once block instances are configuration
- * entities.
- * @todo
* Add support for creating custom block instances.
*/
- protected function drupalPlaceBlock($plugin_id, array $settings = array(), $theme = NULL) {
- // Confirm that the active user has permission to add the block instance.
- // @todo Remove this check once it is possible to do this programmatically.
- if (!empty($this->loggedInUser) && !user_access('administer blocks', $this->loggedInUser)) {
- $this->fail('The logged in user does not have permission to administer blocks.');
- return FALSE;
- }
-
- // If no theme was specified, use the default theme.
- $theme = $theme ?: variable_get('theme_default', 'stark');
-
- // Populate some default block settings.
- $settings += array(
- 'title' => $this->randomName(8),
- 'machine_name' => strtolower($this->randomName(8)),
+ protected function drupalPlaceBlock($plugin_id, array $values = array(), array $settings = array()) {
+ $values += array(
+ 'plugin' => $plugin_id,
+ 'label' => $this->randomName(8),
'region' => 'sidebar_first',
+ 'theme' => variable_get('theme_default', 'stark'),
+ 'machine_name' => strtolower($this->randomName(8)),
+ 'settings' => $settings,
);
-
- // Submit the block instance configuration.
- $this->drupalPost('admin/structure/block/manage/' . $plugin_id . '/' . $theme, $settings, t('Save block'));
- $this->assertText(
- t('The block configuration has been saved.'),
- format_string(
- '%plugin block instance added for %theme',
- array(
- '%plugin' => $plugin_id,
- '%theme' => $theme,
- )
- )
- );
-
- // Return the created block instance.
- $instance_id = "plugin.core.block.$theme." . $settings['machine_name'];
- $manager = $this->container->get('plugin.manager.block');
- $block = $manager->getInstance(array('config' => $instance_id));
- return $block->getConfig();
+ // Build the ID out of the theme and machine_name.
+ $values['id'] = $values['theme'] . '.' . $values['machine_name'];
+ $block = entity_create('block', $values);
+ $block->save();
+ return $block;
}
/**
diff --git a/core/modules/statistics/lib/Drupal/statistics/Plugin/block/block/StatisticsPopularBlock.php b/core/modules/statistics/lib/Drupal/statistics/Plugin/block/block/StatisticsPopularBlock.php
index 8c9fdf6..3fc4099 100644
--- a/core/modules/statistics/lib/Drupal/statistics/Plugin/block/block/StatisticsPopularBlock.php
+++ b/core/modules/statistics/lib/Drupal/statistics/Plugin/block/block/StatisticsPopularBlock.php
@@ -10,6 +10,7 @@
use Drupal\block\BlockBase;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
+use Drupal\block\Plugin\Core\Entity\Block;
/**
* Provides a 'Popular content' block.
@@ -118,7 +119,7 @@ public function blockSubmit($form, &$form_state) {
/**
* Implements \Drupal\block\BlockBase::blockBuild().
*/
- public function blockBuild() {
+ public function blockBuild(Block $entity) {
$content = array();
if ($this->day_list) {
diff --git a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsReportsTest.php b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsReportsTest.php
index 1843c8b..3c59631 100644
--- a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsReportsTest.php
+++ b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsReportsTest.php
@@ -72,8 +72,7 @@ function testAccessLogging() {
*/
function testPopularContentBlock() {
// Clear the block cache to load the Statistics module's block definitions.
- $manager = $this->container->get('plugin.manager.block');
- $manager->clearCachedDefinitions();
+ $this->container->get('plugin.manager.block')->clearCachedDefinitions();
// Visit a node to have something show up in the block.
$node = $this->drupalCreateNode(array('type' => 'page', 'uid' => $this->blocking_user->uid));
@@ -87,11 +86,10 @@ function testPopularContentBlock() {
drupal_http_request($stats_path, array('method' => 'POST', 'data' => $post, 'headers' => $headers, 'timeout' => 10000));
// Configure and save the block.
- $this->drupalPlaceBlock('statistics_popular_block', array(
- 'title' => 'Popular content',
- 'statistics_block_top_day_num' => 3,
- 'statistics_block_top_all_num' => 3,
- 'statistics_block_top_last_num' => 3,
+ $this->drupalPlaceBlock('statistics_popular_block', array('label' => 'Popular content'), array(
+ 'top_day_num' => 3,
+ 'top_all_num' => 3,
+ 'top_last_num' => 3,
));
// Get some page and check if the block is displayed.
diff --git a/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemHelpBlock.php b/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemHelpBlock.php
index 6026f83..9b8d75c 100644
--- a/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemHelpBlock.php
+++ b/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemHelpBlock.php
@@ -10,6 +10,7 @@
use Drupal\block\BlockBase;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
+use Drupal\block\Plugin\Core\Entity\Block;
/**
* Provides a 'System Help' block.
@@ -40,7 +41,7 @@ public function blockAccess() {
/**
* Implements \Drupal\block\BlockBase::blockBuild().
*/
- public function blockBuild() {
+ public function blockBuild(Block $entity) {
return array(
'#children' => $this->help,
);
diff --git a/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemMainBlock.php b/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemMainBlock.php
index 8b40092..0c8a708 100644
--- a/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemMainBlock.php
+++ b/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemMainBlock.php
@@ -10,6 +10,7 @@
use Drupal\block\BlockBase;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
+use Drupal\block\Plugin\Core\Entity\Block;
/**
* Provides a 'Main page content' block.
@@ -25,7 +26,7 @@ class SystemMainBlock extends BlockBase {
/**
* Implements \Drupal\block\BlockBase::blockBuild().
*/
- public function blockBuild() {
+ public function blockBuild(Block $entity) {
return array(
drupal_set_page_content()
);
diff --git a/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemMenuBlock.php b/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemMenuBlock.php
index 0307257..6087fa7 100644
--- a/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemMenuBlock.php
+++ b/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemMenuBlock.php
@@ -10,6 +10,7 @@
use Drupal\block\BlockBase;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
+use Drupal\block\Plugin\Core\Entity\Block;
/**
* Provides a 'System Menu' block.
@@ -35,7 +36,7 @@ public function blockAccess() {
/**
* Implements \Drupal\block\BlockBase::blockBuild().
*/
- public function blockBuild() {
+ public function blockBuild(Block $entity) {
list($plugin, $derivative) = explode(':', $this->getPluginId());
// Derivatives are prefixed with 'menu-'.
$menu = substr($derivative, 5);
diff --git a/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemPoweredByBlock.php b/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemPoweredByBlock.php
index b363725..7fe9d29 100644
--- a/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemPoweredByBlock.php
+++ b/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemPoweredByBlock.php
@@ -10,6 +10,7 @@
use Drupal\block\BlockBase;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
+use Drupal\block\Plugin\Core\Entity\Block;
/**
* Provides a 'Powered by Drupal' block.
@@ -25,7 +26,7 @@ class SystemPoweredByBlock extends BlockBase {
/**
* Implements \Drupal\block\BlockBase::blockBuild().
*/
- public function blockBuild() {
+ public function blockBuild(Block $entity) {
return array(
'#children' => theme('system_powered_by'),
);
diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php
index 8f16e45..a5480ee 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php
@@ -29,7 +29,7 @@ class EntityCrudHookTest extends WebTestBase {
*
* @var array
*/
- public static $modules = array('entity_crud_hook_test', 'taxonomy', 'comment', 'file', 'entity_test');
+ public static $modules = array('entity_crud_hook_test', 'taxonomy', 'block_test', 'block', 'comment', 'file', 'entity_test');
protected $ids = array();
@@ -67,6 +67,54 @@ protected function assertHookMessageOrder($messages) {
}
/**
+ * Tests hook invocations for CRUD operations on blocks.
+ */
+ public function testBlockHooks() {
+ $entity = entity_create('block', array(
+ 'id' => 'stark.test_html_id',
+ 'plugin' => 'test_html_id',
+ ));
+ $_SESSION['entity_crud_hook_test'] = array();
+ $entity->save();
+
+ $this->assertHookMessageOrder(array(
+ 'entity_crud_hook_test_block_presave called',
+ 'entity_crud_hook_test_entity_presave called for type block',
+ 'entity_crud_hook_test_block_insert called',
+ 'entity_crud_hook_test_entity_insert called for type block',
+ ));
+
+ $_SESSION['entity_crud_hook_test'] = array();
+ $entity = entity_load('block', $entity->id());
+
+ $this->assertHookMessageOrder(array(
+ 'entity_crud_hook_test_entity_load called for type block',
+ 'entity_crud_hook_test_block_load called',
+ ));
+
+ $_SESSION['entity_crud_hook_test'] = array();
+ $entity->label = 'New label';
+ $entity->save();
+
+ $this->assertHookMessageOrder(array(
+ 'entity_crud_hook_test_block_presave called',
+ 'entity_crud_hook_test_entity_presave called for type block',
+ 'entity_crud_hook_test_block_update called',
+ 'entity_crud_hook_test_entity_update called for type block',
+ ));
+
+ $_SESSION['entity_crud_hook_test'] = array();
+ $entity->delete();
+
+ $this->assertHookMessageOrder(array(
+ 'entity_crud_hook_test_block_predelete called',
+ 'entity_crud_hook_test_entity_predelete called for type block',
+ 'entity_crud_hook_test_block_delete called',
+ 'entity_crud_hook_test_entity_delete called for type block',
+ ));
+ }
+
+ /**
* Tests hook invocations for CRUD operations on comments.
*/
public function testCommentHooks() {
diff --git a/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php b/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php
index 9c51a89..88f188a 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php
@@ -47,7 +47,8 @@ function setUp() {
'region' => 'content',
);
$this->drupalPlaceBlock('system_menu_block:menu-tools', $settings);
- $this->drupalPlaceBlock('system_menu_block:menu-tools', $settings, config('system.theme')->get('admin'));
+ $settings['theme'] = config('system.theme')->get('admin');
+ $this->drupalPlaceBlock('system_menu_block:menu-tools', $settings);
}
/**
diff --git a/core/modules/system/lib/Drupal/system/Tests/System/AccessDeniedTest.php b/core/modules/system/lib/Drupal/system/Tests/System/AccessDeniedTest.php
index dc555cb..7c8c85b 100644
--- a/core/modules/system/lib/Drupal/system/Tests/System/AccessDeniedTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/System/AccessDeniedTest.php
@@ -82,7 +82,7 @@ function testAccessDenied() {
$edit = array(
'region' => -1,
);
- $this->drupalPost('admin/structure/block/manage/plugin.core.block.stark.login/stark/configure', $edit, t('Save block'));
+ $this->drupalPost('admin/structure/block/manage/stark.login/configure', $edit, t('Save block'));
// Check that we can log in from the 403 page.
$this->drupalLogout();
diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/BlockUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/BlockUpgradePathTest.php
index 1778284..3314554 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/BlockUpgradePathTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/BlockUpgradePathTest.php
@@ -35,23 +35,27 @@ public function setUp() {
public function testBlockUpgradeTitleLength() {
$this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
+ // WebTestBase::drupalPlaceBlock() uses the API directly, which doesn't
+ // output validation errors or success messages, so create the blocks from
+ // the UI.
+
// Add a block instance with a 255-character title.
- $title = $this->randomName(255);
- $this->drupalPlaceBlock('system_powered_by_block', array('title' => $title));
// Confirm that the custom block has been created, and title matches input.
- $this->drupalGet('');
- $this->assertText($title, 'Block with title longer than 64 characters successfully created.');
+ $settings = array(
+ 'label' => $this->randomName(255),
+ 'machine_name' => strtolower($this->randomName(8)),
+ 'region' => 'sidebar_first',
+ );
+ $this->drupalPost('admin/structure/block/add/system_powered_by_block/' . variable_get('theme_default', 'stark'), $settings, t('Save block'));
+ $this->assertText($settings['label'], 'Block with title longer than 64 characters successfully created.');
// Try to add a block with a title over 255 characters.
- // WebTestBase::drupalPlaceBlock() asserts that the block is created
- // successfully. In this case we expect the block creation to fail, so
- // create a new instance of the block manually.
$settings = array(
- 'title' => $this->randomName(256),
+ 'label' => $this->randomName(256),
'machine_name' => strtolower($this->randomName(8)),
'region' => 'sidebar_first',
);
- $this->drupalPost('admin/structure/block/manage/system_powered_by_block/' . variable_get('theme_default', 'stark'), $settings, t('Save block'));
+ $this->drupalPost('admin/structure/block/add/system_powered_by_block/' . variable_get('theme_default', 'stark'), $settings, t('Save block'));
// Confirm that the custom block cannot be created with title longer than
// the maximum number of characters.
diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/UserRoleUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/UserRoleUpgradePathTest.php
index 4e968d2..f87c19f 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/UserRoleUpgradePathTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/UserRoleUpgradePathTest.php
@@ -58,7 +58,7 @@ public function testRoleUpgrade() {
// Check that the role visibility setting for the who's online block still
// exists.
- $this->drupalGet('admin/structure/block/manage/user_online_block/bartik');
+ $this->drupalGet('admin/structure/block/add/user_online_block/bartik');
// @todo Blocks are not being upgraded.
// $this->assertFieldChecked('edit-visibility-role-roles-5', "Who's online block visibility setting is correctly set for the long role name.");
diff --git a/core/modules/system/system.module b/core/modules/system/system.module
index cdf7b90..65b1914 100644
--- a/core/modules/system/system.module
+++ b/core/modules/system/system.module
@@ -7,7 +7,7 @@
use Drupal\Core\Utility\ModuleInfo;
use Drupal\Core\TypedData\Primitive;
-
+use Drupal\system\Plugin\block\block\SystemMenuBlock;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
@@ -2634,7 +2634,7 @@ function system_preprocess_block(&$variables) {
// System menu blocks should get the same class as menu module blocks.
default:
- if ($variables['block']->class == 'Drupal\\system\\Plugin\\block\\block\\SystemMenuBlock') {
+ if ($variables['elements']['#block']->getPlugin() instanceof SystemMenuBlock) {
$variables['attributes_array']['role'] = 'navigation';
$variables['classes_array'][] = 'block-menu';
}
diff --git a/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module b/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module
index 8a1e43c..f2bb297 100644
--- a/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module
+++ b/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module
@@ -15,6 +15,13 @@ function entity_crud_hook_test_entity_presave(EntityInterface $entity) {
}
/**
+ * Implements hook_block_presave().
+ */
+function entity_crud_hook_test_block_presave() {
+ $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called');
+}
+
+/**
* Implements hook_comment_presave().
*/
function entity_crud_hook_test_comment_presave() {
@@ -64,6 +71,13 @@ function entity_crud_hook_test_entity_insert(EntityInterface $entity) {
}
/**
+ * Implements hook_block_insert().
+ */
+function entity_crud_hook_test_block_insert() {
+ $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called');
+}
+
+/**
* Implements hook_comment_insert().
*/
function entity_crud_hook_test_comment_insert() {
@@ -113,6 +127,13 @@ function entity_crud_hook_test_entity_load(array $entities, $type) {
}
/**
+ * Implements hook_block_load().
+ */
+function entity_crud_hook_test_block_load() {
+ $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called');
+}
+
+/**
* Implements hook_comment_load().
*/
function entity_crud_hook_test_comment_load() {
@@ -162,6 +183,13 @@ function entity_crud_hook_test_entity_update(EntityInterface $entity) {
}
/**
+ * Implements hook_block_update().
+ */
+function entity_crud_hook_test_block_update() {
+ $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called');
+}
+
+/**
* Implements hook_comment_update().
*/
function entity_crud_hook_test_comment_update() {
@@ -211,6 +239,13 @@ function entity_crud_hook_test_entity_predelete(EntityInterface $entity) {
}
/**
+ * Implements hook_block_predelete().
+ */
+function entity_crud_hook_test_block_predelete() {
+ $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called');
+}
+
+/**
* Implements hook_comment_predelete().
*/
function entity_crud_hook_test_comment_predelete() {
@@ -260,6 +295,13 @@ function entity_crud_hook_test_entity_delete(EntityInterface $entity) {
}
/**
+ * Implements hook_block_delete().
+ */
+function entity_crud_hook_test_block_delete() {
+ $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called');
+}
+
+/**
* Implements hook_comment_delete().
*/
function entity_crud_hook_test_comment_delete() {
diff --git a/core/modules/user/lib/Drupal/user/Plugin/block/block/UserLoginBlock.php b/core/modules/user/lib/Drupal/user/Plugin/block/block/UserLoginBlock.php
index 51bc8ee..996e15d 100644
--- a/core/modules/user/lib/Drupal/user/Plugin/block/block/UserLoginBlock.php
+++ b/core/modules/user/lib/Drupal/user/Plugin/block/block/UserLoginBlock.php
@@ -10,6 +10,7 @@
use Drupal\block\BlockBase;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
+use Drupal\block\Plugin\Core\Entity\Block;
/**
* Provides a 'User login' block.
@@ -32,7 +33,7 @@ public function blockAccess() {
/**
* Implements \Drupal\block\BlockBase::blockBuild().
*/
- public function blockBuild() {
+ public function blockBuild(Block $entity) {
$form = drupal_get_form('user_login_form');
unset($form['name']['#attributes']['autofocus']);
unset($form['name']['#description']);
diff --git a/core/modules/user/lib/Drupal/user/Plugin/block/block/UserNewBlock.php b/core/modules/user/lib/Drupal/user/Plugin/block/block/UserNewBlock.php
index 7f97df6..2ea4b89 100644
--- a/core/modules/user/lib/Drupal/user/Plugin/block/block/UserNewBlock.php
+++ b/core/modules/user/lib/Drupal/user/Plugin/block/block/UserNewBlock.php
@@ -10,6 +10,7 @@
use Drupal\block\BlockBase;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
+use Drupal\block\Plugin\Core\Entity\Block;
/**
* Provides a "Who's new" block.
@@ -64,7 +65,7 @@ public function blockSubmit($form, &$form_state) {
/**
* Implements \Drupal\block\BlockBase::blockBuild().
*/
- public function blockBuild() {
+ public function blockBuild(Block $entity) {
// Retrieve a list of new users who have accessed the site successfully.
$items = db_query_range('SELECT uid, name FROM {users} WHERE status <> 0 AND access <> 0 ORDER BY created DESC', 0, $this->configuration['whois_new_count'])->fetchAll();
$build = array(
diff --git a/core/modules/user/lib/Drupal/user/Plugin/block/block/UserOnlineBlock.php b/core/modules/user/lib/Drupal/user/Plugin/block/block/UserOnlineBlock.php
index 75f23f0..aee6ce1 100644
--- a/core/modules/user/lib/Drupal/user/Plugin/block/block/UserOnlineBlock.php
+++ b/core/modules/user/lib/Drupal/user/Plugin/block/block/UserOnlineBlock.php
@@ -10,6 +10,7 @@
use Drupal\block\BlockBase;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
+use Drupal\block\Plugin\Core\Entity\Block;
/**
* Provides a "Who's online" block.
@@ -78,7 +79,7 @@ public function blockSubmit($form, &$form_state) {
/**
* Implements \Drupal\block\BlockBase::blockBuild().
*/
- public function blockBuild() {
+ public function blockBuild(Block $entity) {
// Count users active within the defined period.
$interval = REQUEST_TIME - $this->configuration['seconds_online'];
diff --git a/core/modules/user/lib/Drupal/user/Tests/UserBlocksTests.php b/core/modules/user/lib/Drupal/user/Tests/UserBlocksTests.php
index a2f027f..50a79ea 100644
--- a/core/modules/user/lib/Drupal/user/Tests/UserBlocksTests.php
+++ b/core/modules/user/lib/Drupal/user/Tests/UserBlocksTests.php
@@ -80,9 +80,8 @@ function testUserLoginBlock() {
* Test the Who's Online block.
*/
function testWhosOnlineBlock() {
- $plugin_id = 'plugin.core.block.' . variable_get('theme_default', 'stark') . '.online';
- $block = $this->container->get('plugin.manager.block')->getInstance(array('config' => $plugin_id));
- $config = $block->getConfig();
+ $block = entity_load('block', 'stark.online');
+ $config = $block->get('settings');
// Generate users.
$user1 = $this->drupalCreateUser(array());
@@ -100,7 +99,7 @@ function testWhosOnlineBlock() {
$this->updateAccess($this->adminUser->uid, $inactive_time);
// Test block output.
- $content = $block->build();
+ $content = entity_view($block, 'block');
$this->drupalSetContent(render($content));
$this->assertRaw(t('2 users'), 'Correct number of online users (2 users).');
$this->assertText($user1->name, 'Active user 1 found in online list.');
diff --git a/core/modules/views/lib/Drupal/views/Plugin/block/block/ViewsBlock.php b/core/modules/views/lib/Drupal/views/Plugin/block/block/ViewsBlock.php
index 296212c..7939f5c 100644
--- a/core/modules/views/lib/Drupal/views/Plugin/block/block/ViewsBlock.php
+++ b/core/modules/views/lib/Drupal/views/Plugin/block/block/ViewsBlock.php
@@ -11,6 +11,7 @@
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
+use Drupal\block\Plugin\Core\Entity\Block;
/**
* Provides a generic Views block.
@@ -71,10 +72,10 @@ public function blockForm($form, &$form_state) {
/**
* Implements \Drupal\block\BlockBase::blockBuild().
*/
- public function blockBuild() {
+ public function blockBuild(Block $block) {
$output = $this->view->executeDisplay($this->displayID);
- // Set the subject to the title configured in the view.
- $this->configuration['subject'] = filter_xss_admin($this->view->getTitle());
+ // Set the label to the title configured in the view.
+ $block->set('label', filter_xss_admin($this->view->getTitle()));
// Before returning the block output, convert it to a renderable array
// with contextual links.
views_add_block_contextual_links($output, $this->view, $this->displayID);
diff --git a/core/modules/views/lib/Drupal/views/Plugin/block/block/ViewsExposedFilterBlock.php b/core/modules/views/lib/Drupal/views/Plugin/block/block/ViewsExposedFilterBlock.php
index 2d51c25..40baebb 100644
--- a/core/modules/views/lib/Drupal/views/Plugin/block/block/ViewsExposedFilterBlock.php
+++ b/core/modules/views/lib/Drupal/views/Plugin/block/block/ViewsExposedFilterBlock.php
@@ -9,6 +9,7 @@
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
+use Drupal\block\Plugin\Core\Entity\Block;
/**
* Provides a 'Views Exposed Filter' block.
@@ -25,7 +26,7 @@ class ViewsExposedFilterBlock extends ViewsBlock {
/**
* Implements \Drupal\block\BlockBase::blockBuild().
*/
- public function blockBuild() {
+ public function blockBuild(Block $entity) {
$type = 'exp';
$output = $this->view->display_handler->viewSpecialBlocks($type);
// Before returning the block output, convert it to a renderable array with
diff --git a/core/profiles/standard/config/plugin.core.block.bartik.content.yml b/core/profiles/standard/config/plugin.core.block.bartik.content.yml
index e10f903..7f1a9f8 100644
--- a/core/profiles/standard/config/plugin.core.block.bartik.content.yml
+++ b/core/profiles/standard/config/plugin.core.block.bartik.content.yml
@@ -1,6 +1,8 @@
-id: system_main_block
+id: bartik.content
+plugin: system_main_block
status: '1'
-cache: '-1'
+settings:
+ cache: '-1'
visibility:
path:
visibility: '0'
@@ -12,7 +14,8 @@ visibility:
article: '0'
page: '0'
visibility__active_tab: edit-visibility-path
-subject: ''
+label: ''
module: system
region: content
weight: '0'
+langcode: und
diff --git a/core/profiles/standard/config/plugin.core.block.bartik.footer.yml b/core/profiles/standard/config/plugin.core.block.bartik.footer.yml
index 7b6f9b7..4496313 100644
--- a/core/profiles/standard/config/plugin.core.block.bartik.footer.yml
+++ b/core/profiles/standard/config/plugin.core.block.bartik.footer.yml
@@ -1,7 +1,9 @@
-id: 'system_menu_block:menu-footer'
+id: bartik.footer
+plugin: 'system_menu_block:menu-footer'
status: '1'
-cache: '-1'
-subject: 'Footer menu'
+settings:
+ cache: '-1'
+label: 'Footer menu'
visibility:
path:
visibility: '0'
@@ -16,3 +18,4 @@ visibility:
module: system
region: footer
weight: '0'
+langcode: und
diff --git a/core/profiles/standard/config/plugin.core.block.bartik.help.yml b/core/profiles/standard/config/plugin.core.block.bartik.help.yml
index a5c4467..58d10a3 100644
--- a/core/profiles/standard/config/plugin.core.block.bartik.help.yml
+++ b/core/profiles/standard/config/plugin.core.block.bartik.help.yml
@@ -1,6 +1,8 @@
-id: system_help_block
+id: bartik.help
+plugin: system_help_block
status: '1'
-cache: '-1'
+settings:
+ cache: '-1'
visibility:
path:
visibility: '0'
@@ -12,7 +14,8 @@ visibility:
article: '0'
page: '0'
visibility__active_tab: edit-visibility-path
-subject: ''
+label: ''
module: system
region: help
weight: '0'
+langcode: und
diff --git a/core/profiles/standard/config/plugin.core.block.bartik.login.yml b/core/profiles/standard/config/plugin.core.block.bartik.login.yml
index 8d8923a..21d73d8 100644
--- a/core/profiles/standard/config/plugin.core.block.bartik.login.yml
+++ b/core/profiles/standard/config/plugin.core.block.bartik.login.yml
@@ -1,7 +1,8 @@
-id: user_login_block
+id: bartik.login
whois_new_count: '5'
status: '1'
-cache: '-1'
+settings:
+ cache: '-1'
visibility:
path:
visibility: '0'
@@ -13,7 +14,9 @@ visibility:
article: '0'
page: '0'
visibility__active_tab: edit-visibility-path
-subject: 'User login'
+label: 'User login'
module: user
region: sidebar_first
weight: '0'
+plugin: user_login_block
+langcode: und
diff --git a/core/profiles/standard/config/plugin.core.block.bartik.powered.yml b/core/profiles/standard/config/plugin.core.block.bartik.powered.yml
index 1f9dc52..446e51a 100644
--- a/core/profiles/standard/config/plugin.core.block.bartik.powered.yml
+++ b/core/profiles/standard/config/plugin.core.block.bartik.powered.yml
@@ -1,6 +1,8 @@
-id: system_powered_by_block
+id: bartik.powered
+plugin: system_powered_by_block
status: '1'
-cache: '-1'
+settings:
+ cache: '-1'
visibility:
path:
visibility: '0'
@@ -12,7 +14,8 @@ visibility:
article: '0'
page: '0'
visibility__active_tab: edit-visibility-path
-subject: ''
+label: ''
module: system
region: footer
weight: '10'
+langcode: und
diff --git a/core/profiles/standard/config/plugin.core.block.bartik.search.yml b/core/profiles/standard/config/plugin.core.block.bartik.search.yml
index d314a49..3dcda34 100644
--- a/core/profiles/standard/config/plugin.core.block.bartik.search.yml
+++ b/core/profiles/standard/config/plugin.core.block.bartik.search.yml
@@ -1,6 +1,8 @@
-id: search_form_block
+id: bartik.search
+plugin: search_form_block
status: '1'
-cache: '-1'
+settings:
+ cache: '-1'
visibility:
path:
visibility: '0'
@@ -12,7 +14,8 @@ visibility:
article: '0'
page: '0'
visibility__active_tab: edit-visibility-path
-subject: 'Search'
+label: 'Search'
module: search
region: sidebar_first
weight: '-1'
+langcode: und
diff --git a/core/profiles/standard/config/plugin.core.block.bartik.tools.yml b/core/profiles/standard/config/plugin.core.block.bartik.tools.yml
index d6a38c9..44e3aeb 100644
--- a/core/profiles/standard/config/plugin.core.block.bartik.tools.yml
+++ b/core/profiles/standard/config/plugin.core.block.bartik.tools.yml
@@ -1,6 +1,8 @@
-id: 'system_menu_block:menu-tools'
+id: bartik.tools
+plugin: 'system_menu_block:menu-tools'
status: '1'
-cache: '-1'
+settings:
+ cache: '-1'
visibility:
path:
visibility: '0'
@@ -12,7 +14,8 @@ visibility:
article: '0'
page: '0'
visibility__active_tab: edit-visibility-path
-subject: 'Tools'
+label: 'Tools'
module: system
region: sidebar_first
weight: '0'
+langcode: und
diff --git a/core/profiles/standard/config/plugin.core.block.seven.content.yml b/core/profiles/standard/config/plugin.core.block.seven.content.yml
index e10f903..675f718 100644
--- a/core/profiles/standard/config/plugin.core.block.seven.content.yml
+++ b/core/profiles/standard/config/plugin.core.block.seven.content.yml
@@ -1,6 +1,8 @@
-id: system_main_block
+id: seven.content
+plugin: system_main_block
status: '1'
-cache: '-1'
+settings:
+ cache: '-1'
visibility:
path:
visibility: '0'
@@ -12,7 +14,8 @@ visibility:
article: '0'
page: '0'
visibility__active_tab: edit-visibility-path
-subject: ''
+label: ''
module: system
region: content
weight: '0'
+langcode: und
diff --git a/core/profiles/standard/config/plugin.core.block.seven.help.yml b/core/profiles/standard/config/plugin.core.block.seven.help.yml
index a5c4467..72c4509 100644
--- a/core/profiles/standard/config/plugin.core.block.seven.help.yml
+++ b/core/profiles/standard/config/plugin.core.block.seven.help.yml
@@ -1,6 +1,8 @@
-id: system_help_block
+id: seven.help
+plugin: system_help_block
status: '1'
-cache: '-1'
+settings:
+ cache: '-1'
visibility:
path:
visibility: '0'
@@ -12,7 +14,8 @@ visibility:
article: '0'
page: '0'
visibility__active_tab: edit-visibility-path
-subject: ''
+label: ''
module: system
region: help
weight: '0'
+langcode: und
diff --git a/core/profiles/standard/config/plugin.core.block.seven.login.yml b/core/profiles/standard/config/plugin.core.block.seven.login.yml
index 8c4eca5..c35ba59 100644
--- a/core/profiles/standard/config/plugin.core.block.seven.login.yml
+++ b/core/profiles/standard/config/plugin.core.block.seven.login.yml
@@ -1,7 +1,8 @@
-id: user_login_block
-whois_new_count: '5'
+id: seven.login
+plugin: user_login_block
status: '1'
-cache: '-1'
+settings:
+ cache: '-1'
visibility:
path:
visibility: '0'
@@ -13,7 +14,8 @@ visibility:
article: '0'
page: '0'
visibility__active_tab: edit-visibility-path
-subject: 'User login'
+label: 'User login'
module: user
region: content
weight: '10'
+langcode: und
diff --git a/core/profiles/testing/config/plugin.core.block.stark.admin.yml b/core/profiles/testing/config/plugin.core.block.stark.admin.yml
index 960e2cb..5ca8d1f 100644
--- a/core/profiles/testing/config/plugin.core.block.stark.admin.yml
+++ b/core/profiles/testing/config/plugin.core.block.stark.admin.yml
@@ -1,6 +1,8 @@
-id: 'system_menu_block:menu-admin'
+id: stark.admin
+plugin: 'system_menu_block:menu-admin'
status: '1'
-cache: '-1'
+settings:
+ cache: '-1'
visibility:
path:
visibility: '0'
@@ -12,7 +14,8 @@ visibility:
article: '0'
page: '0'
visibility__active_tab: edit-visibility-path
-subject: ''
+label: ''
module: system
region: sidebar_first
weight: '0'
+langcode: und
diff --git a/core/profiles/testing/config/plugin.core.block.stark.online.yml b/core/profiles/testing/config/plugin.core.block.stark.online.yml
index 3b3f5c5..a00e02d 100644
--- a/core/profiles/testing/config/plugin.core.block.stark.online.yml
+++ b/core/profiles/testing/config/plugin.core.block.stark.online.yml
@@ -1,11 +1,14 @@
-id: user_online_block
-properties:
- administrative: '1'
-seconds_online: '900'
-max_list_count: '10'
+id: stark.online
+label: 'Who''s online'
+plugin: user_online_block
+settings:
+ properties:
+ administrative: '1'
+ seconds_online: '900'
+ max_list_count: '10'
+ cache: '-1'
status: '1'
-cache: '-1'
-subject: 'Who''s online'
+label: 'Who''s online'
visibility:
path:
visibility: '0'
@@ -21,3 +24,4 @@ visibility:
module: user
region: sidebar_first
weight: '0'
+langcode: und
diff --git a/core/profiles/testing/config/plugin.core.block.stark.tools.yml b/core/profiles/testing/config/plugin.core.block.stark.tools.yml
index 5e8b188..d68441e 100644
--- a/core/profiles/testing/config/plugin.core.block.stark.tools.yml
+++ b/core/profiles/testing/config/plugin.core.block.stark.tools.yml
@@ -1,6 +1,8 @@
-id: 'system_menu_block:menu-tools'
+id: stark.tools
+plugin: 'system_menu_block:menu-tools'
status: '1'
-cache: '-1'
+settings:
+ cache: '-1'
visibility:
path:
visibility: '0'
@@ -12,7 +14,8 @@ visibility:
article: '0'
page: '0'
visibility__active_tab: edit-visibility-path
-subject: ''
+label: ''
module: system
region: sidebar_first
weight: '0'
+langcode: und