diff --git a/core/modules/block/block.module b/core/modules/block/block.module index cfbad28..a88c717 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -302,14 +302,12 @@ function _block_get_renderable_region($list = array()) { } } else { - $key_components = explode('.', $key); - $id = array_pop($key_components); $build[$key] = array( '#block' => $block, '#weight' => $block->get('weight'), '#pre_render' => array('_block_get_renderable_block'), '#cache' => array( - 'keys' => array($id, $settings['module']), + 'keys' => array($key, $settings['module']), 'granularity' => $settings['cache'], 'bin' => 'block', 'tags' => array('content' => TRUE), @@ -400,9 +398,15 @@ function block_theme_initialize($theme) { $regions = system_region_list($theme, REGIONS_VISIBLE); $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); + if (strpos($default_theme_block_id, $default_theme . '_') === 0) { + $id = str_replace($default_theme, $theme, $default_theme_block_id); + } + else { + $id = $theme . '_' . $default_theme_block_id; + } $block = $default_theme_block->createDuplicate(); - $block->set('id', $theme . '.' . $machine_name); + $block->set('id', $id); + $block->set('theme', $theme); // If the region isn't supported by the theme, assign the block to the // theme's default region. if (!isset($regions[$block->get('region')])) { @@ -552,10 +556,8 @@ function template_preprocess_block(&$variables) { } // Create a valid HTML ID and make sure it is unique. if ($id = $variables['elements']['#block']->id()) { - $config_id = explode('.', $id); - $machine_name = array_pop($config_id); - $variables['attributes']['id'] = drupal_html_id('block-' . $machine_name); - $variables['theme_hook_suggestions'][] = 'block__' . $machine_name; + $variables['attributes']['id'] = drupal_html_id('block-' . $id); + $variables['theme_hook_suggestions'][] = 'block__' . $id; } } diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockCreationTest.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockCreationTest.php index 8beda0b..2f1f39e 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockCreationTest.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockCreationTest.php @@ -143,7 +143,7 @@ public function testBlockDelete() { // Place the block. $instance = array( - 'machine_name' => drupal_strtolower($edit['info']), + 'id' => drupal_strtolower($edit['info']), 'settings[label]' => $edit['info'], 'region' => 'sidebar_first', ); diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockFieldTest.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockFieldTest.php index da5ac4f..ec3bd37 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockFieldTest.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockFieldTest.php @@ -101,7 +101,7 @@ public function testBlockFields() { $this->drupalPost(NULL, $edit, t('Save')); // Place the block. $instance = array( - 'machine_name' => drupal_strtolower($edit['info']), + 'id' => drupal_strtolower($edit['info']), 'settings[label]' => $edit['info'], 'region' => 'sidebar_first', ); diff --git a/core/modules/block/lib/Drupal/block/BlockFormController.php b/core/modules/block/lib/Drupal/block/BlockFormController.php index f562a68..4be76ef 100644 --- a/core/modules/block/lib/Drupal/block/BlockFormController.php +++ b/core/modules/block/lib/Drupal/block/BlockFormController.php @@ -21,13 +21,9 @@ class BlockFormController extends EntityFormController { public function form(array $form, array &$form_state) { $entity = $this->entity; $form['#tree'] = TRUE; - $form['id'] = array( - '#type' => 'value', - '#value' => $entity->id(), - ); $form['settings'] = $entity->getPlugin()->form(array(), $form_state); - $form['machine_name'] = array( + $form['id'] = array( '#type' => 'machine_name', '#title' => t('Machine name'), '#maxlength' => 64, @@ -193,14 +189,6 @@ protected function actions(array $form, array &$form_state) { public function validate(array $form, array &$form_state) { parent::validate($form, $form_state); - $entity = $this->entity; - if ($entity->isNew()) { - form_set_value($form['id'], $entity->get('theme') . '.' . $form_state['values']['machine_name'], $form_state); - } - if (!empty($form['machine_name']['#disabled'])) { - $config_id = explode('.', $form_state['values']['machine_name']); - $form_state['values']['machine_name'] = array_pop($config_id); - } $form_state['values']['visibility']['role']['roles'] = array_filter($form_state['values']['visibility']['role']['roles']); // The Block Entity form puts all block plugin form elements in the // settings form element, so just pass that to the block for validation. @@ -208,7 +196,7 @@ public function validate(array $form, array &$form_state) { 'values' => &$form_state['values']['settings'] ); // Call the plugin validate handler. - $entity->getPlugin()->validate($form, $settings); + $this->entity->getPlugin()->validate($form, $settings); } /** @@ -217,21 +205,20 @@ public function validate(array $form, array &$form_state) { public function submit(array $form, array &$form_state) { parent::submit($form, $form_state); - $entity = $this->entity; // The Block Entity form puts all block plugin form elements in the // settings form element, so just pass that to the block for submission. $settings = array( 'values' => &$form_state['values']['settings'] ); // Call the plugin submit handler. - $entity->getPlugin()->submit($form, $settings); + $this->entity->getPlugin()->submit($form, $settings); // Save the settings of the plugin. - $entity->save(); + $this->entity->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:' . $entity->get('theme'); + $form_state['redirect'] = 'admin/structure/block/list/block_plugin_ui:' . $this->entity->get('theme'); } } 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 index 1d3cca8..c99be06 100644 --- a/core/modules/block/lib/Drupal/block/Plugin/Core/Entity/Block.php +++ b/core/modules/block/lib/Drupal/block/Plugin/Core/Entity/Block.php @@ -136,23 +136,12 @@ public function label($langcode = NULL) { } /** - * 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() { $properties = parent::getExportProperties(); $names = array( + 'theme', 'region', 'weight', 'plugin', diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockHookOperationTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockHookOperationTest.php index 3621f26..79515d6 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockHookOperationTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockHookOperationTest.php @@ -54,7 +54,7 @@ public function testBlockOperationAlter() { // Get the Block listing. $this->drupalGet('admin/structure/block'); - $test_operation_link = 'admin/structure/block/manage/stark.' . $block_machine_name . '/test_operation'; + $test_operation_link = 'admin/structure/block/manage/' . $block_machine_name . '/test_operation'; // Test if the test_operation link is on the page. $this->assertLinkByHref($test_operation_link); } diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockLanguageTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockLanguageTest.php index 69d5ccd..8874eec 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockLanguageTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockLanguageTest.php @@ -62,7 +62,7 @@ public function testLanguageBlockVisibility() { // Enable a standard block and set the visibility setting for one language. $edit = array( 'visibility[language][langcodes][en]' => TRUE, - 'machine_name' => strtolower($this->randomName(8)), + 'id' => strtolower($this->randomName(8)), 'region' => 'sidebar_first', ); $this->drupalPost('admin/structure/block/add/system_powered_by_block' . '/' . $default_theme, $edit, t('Save block')); diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php index 41b5f4d..8f38d40 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php @@ -80,7 +80,8 @@ protected function createTests() { // Create a block with only required values. $entity = $this->controller->create(array( - 'id' => 'stark.test_block', + 'id' => 'test_block', + 'theme' => 'stark', 'plugin' => 'test_html_id', )); $entity->save(); @@ -88,16 +89,17 @@ protected function createTests() { $this->assertTrue($entity instanceof Block, 'The newly created entity is a Block.'); // Verify all of the block properties. - $actual_properties = config('block.block.stark.test_block')->get(); + $actual_properties = config('block.block.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', + 'id' => 'test_block', 'weight' => '', 'status' => '1', 'langcode' => language_default()->id, + 'theme' => 'stark', 'region' => '-1', 'plugin' => 'test_html_id', 'settings' => array( @@ -117,7 +119,7 @@ protected function createTests() { * Tests the rendering of blocks. */ protected function loadTests() { - $entity = $this->controller->load('stark.test_block'); + $entity = $this->controller->load('test_block'); $this->assertTrue($entity instanceof Block, 'The loaded entity is a Block.'); @@ -133,7 +135,7 @@ protected function loadTests() { */ protected function renderTests() { // Test the rendering of a block. - $entity = entity_load('block', 'stark.test_block'); + $entity = entity_load('block', 'test_block'); $output = entity_view($entity, 'block'); $expected = array(); $expected[] = '
'; @@ -153,7 +155,8 @@ protected function renderTests() { // Test the rendering of a block with a given title. $entity = $this->controller->create(array( - 'id' => 'stark.test_block2', + 'id' => 'test_block2', + 'theme' => 'stark', 'plugin' => 'test_html_id', 'settings' => array( 'label' => 'Powered by Bananas', @@ -182,7 +185,7 @@ protected function renderTests() { * Tests the deleting of blocks. */ protected function deleteTests() { - $entity = $this->controller->load('stark.test_block'); + $entity = $this->controller->load('test_block'); // Ensure that the storage isn't currently empty. $config_storage = $this->container->get('config.storage'); @@ -209,7 +212,7 @@ public function testDefaultBlocks() { $entities = $this->controller->loadMultiple(); $entity = reset($entities); - $this->assertEqual($entity->id(), 'stark.test_block', 'The default test block was loaded.'); + $this->assertEqual($entity->id(), '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 51630ba..fa6faf2 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockTemplateSuggestionsUnitTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockTemplateSuggestionsUnitTest.php @@ -40,7 +40,7 @@ function testBlockThemeHookSuggestions() { $block = entity_create('block', array( 'plugin' => 'system_menu_block:menu-admin', 'region' => 'footer', - 'id' => config('system.theme')->get('default') . '.machinename', + 'id' => 'machinename', )); $variables = array(); diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php index 7f7855d..3911560 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php @@ -32,7 +32,7 @@ function testBlockVisibility() { // Enable a standard block. $default_theme = config('system.theme')->get('default'); $edit = array( - 'machine_name' => strtolower($this->randomName(8)), + 'id' => strtolower($this->randomName(8)), 'region' => 'sidebar_first', 'settings[label]' => $title, ); @@ -73,7 +73,7 @@ function testBlockVisibilityListedEmpty() { // Enable a standard block. $default_theme = config('system.theme')->get('default'); $edit = array( - 'machine_name' => strtolower($this->randomName(8)), + 'id' => strtolower($this->randomName(8)), 'region' => 'sidebar_first', 'settings[label]' => $title, 'visibility[path][visibility]' => BLOCK_VISIBILITY_LISTED, @@ -103,15 +103,14 @@ function testBlock() { $block = array(); $block['id'] = 'system_powered_by_block'; $block['settings[label]'] = $this->randomName(8); - $block['machine_name'] = strtolower($this->randomName(8)); $block['theme'] = config('system.theme')->get('default'); $block['region'] = 'header'; // Set block title to confirm that interface works and override any custom titles. - $this->drupalPost('admin/structure/block/add/' . $block['id'] . '/' . $block['theme'], array('settings[label]' => $block['settings[label]'], 'machine_name' => $block['machine_name'], 'region' => $block['region']), t('Save block')); + $this->drupalPost('admin/structure/block/add/' . $block['id'] . '/' . $block['theme'], array('settings[label]' => $block['settings[label]'], 'id' => $block['id'], '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. - $instance = entity_load('block', $block['theme'] . '.' . $block['machine_name']); + $instance = entity_load('block', $block['id']); $this->assertEqual($instance->label(), $block['settings[label]'], 'Stored block title found.'); @@ -122,7 +121,7 @@ function testBlock() { // Set the block to the disabled region. $edit = array(); - $edit['blocks[' . $block['theme'] . '.' . $block['machine_name'] . '][region]'] = -1; + $edit['blocks[' . $block['id'] . '][region]'] = -1; $this->drupalPost('admin/structure/block', $edit, t('Save blocks')); // Confirm that the block is now listed as disabled. @@ -133,7 +132,7 @@ function testBlock() { $this->assertNoText(t($block['settings[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']), '-', '_'))); + $xpath = $this->buildXPathQuery('//div[@id=:id]/*', array(':id' => 'block-' . str_replace('_', '-', strtolower($block['id'])))); $this->assertNoFieldByXPath($xpath, FALSE, 'Block found in no regions.'); } @@ -144,11 +143,11 @@ function testHideBlockTitle() { $block_name = 'system_powered_by_block'; // Create a random title for the block. $title = $this->randomName(8); - $machine_name = strtolower($this->randomName(8)); + $id = strtolower($this->randomName(8)); // Enable a standard block. $default_theme = variable_get('theme_default', 'stark'); $edit = array( - 'machine_name' => $machine_name, + 'id' => $id, 'region' => 'sidebar_first', 'settings[label]' => $title, ); @@ -161,7 +160,7 @@ function testHideBlockTitle() { $edit = array( 'settings[label_display]' => FALSE, ); - $this->drupalPost('admin/structure/block/manage/' . $default_theme . '.' . $machine_name, $edit, t('Save block')); + $this->drupalPost('admin/structure/block/manage/' . $id, $edit, t('Save block')); $this->assertText('The block configuration has been saved.', 'Block was saved'); $this->drupalGet('user'); @@ -184,7 +183,7 @@ function moveBlockToRegion(array $block, $region) { // Set the created block to a specific region. $block += array('theme' => config('system.theme')->get('default')); $edit = array(); - $edit['blocks[' . $block['theme'] . '.' . $block['machine_name'] . '][region]'] = $region; + $edit['blocks[' . $block['id'] . '][region]'] = $region; $this->drupalPost('admin/structure/block', $edit, t('Save blocks')); // Confirm that the block was moved to the proper region. @@ -197,7 +196,7 @@ function moveBlockToRegion(array $block, $region) { // Confirm that the custom block was found at the proper region. $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($block['machine_name']), '-', '_'), + ':block-id' => 'block-' . str_replace('_', '-', strtolower($block['id'])), )); $this->assertFieldByXPath($xpath, NULL, t('Block found in %region_name region.', array('%region_name' => drupal_html_class($region)))); } @@ -215,7 +214,6 @@ function testBlockRehash() { // Add a test block. $block = array(); $block['id'] = 'test_cache'; - $block['machine_name'] = strtolower($this->randomName(8)); $block['theme'] = config('system.theme')->get('default'); $block['region'] = 'header'; $block = $this->drupalPlaceBlock('test_cache', array('region' => 'header')); @@ -290,7 +288,7 @@ function testBlockModuleDisable() { // that the form still functions as expected. $edit = array( 'settings[label]' => $this->randomName(8), - 'machine_name' => strtolower($this->randomName(8)), + 'id' => strtolower($this->randomName(8)), 'region' => 'sidebar_first', ); $this->drupalPost('admin/structure/block/add/system_powered_by_block/stark', $edit, t('Save block')); @@ -298,7 +296,7 @@ function testBlockModuleDisable() { $this->assertText($edit['settings[label]']); // Update the weight of a block. - $edit = array('blocks[stark.' . $edit['machine_name'] . '][weight]' => -1); + $edit = array('blocks[' . $edit['id'] . '][weight]' => -1); $this->drupalPost('admin/structure/block', $edit, t('Save blocks')); $this->assertText(t('The block settings have been updated.')); @@ -317,13 +315,10 @@ function testBlockModuleDisable() { // correct regions. $this->drupalGet(''); foreach ($regions as $region) { - // @todo Use a proper method for this. - $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), '-', '_'), - )); + ':block-id' => 'block-' . str_replace('_', '-', strtolower($blocks[$region]->id())), + )); $this->assertFieldByXPath($xpath, NULL, format_string('Block %name found in the %region region.', array( '%name' => $blocks[$region]->label(), '%region' => $region, diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockUiTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockUiTest.php index cd9d955..35837f8 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockUiTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockUiTest.php @@ -81,24 +81,24 @@ function testBlockAdminUiPage() { $element = $this->xpath('//*[@id="blocks"]/tbody/tr[' . $values['tr'] . ']/td[1]/text()'); $this->assertTrue((string)$element[0] == $values['label'], 'The "' . $values['label'] . '" block title is set inside the ' . $values['settings']['region'] . ' region.'); // Look for a test block region select form element. - $this->assertField('blocks[stark.' . $values['settings']['machine_name'] . '][region]', 'The block "' . $values['label'] . '" has a region assignment field.'); + $this->assertField('blocks[' . $values['settings']['machine_name'] . '][region]', 'The block "' . $values['label'] . '" has a region assignment field.'); // Move the test block to the header region. - $edit['blocks[stark.' . $values['settings']['machine_name'] . '][region]'] = 'header'; + $edit['blocks[' . $values['settings']['machine_name'] . '][region]'] = 'header'; // Look for a test block weight select form element. - $this->assertField('blocks[stark.' . $values['settings']['machine_name'] . '][weight]', 'The block "' . $values['label'] . '" has a weight assignment field.'); + $this->assertField('blocks[' . $values['settings']['machine_name'] . '][weight]', 'The block "' . $values['label'] . '" has a weight assignment field.'); // Change the test block's weight. - $edit['blocks[stark.' . $values['settings']['machine_name'] . '][weight]'] = $values['test_weight']; + $edit['blocks[' . $values['settings']['machine_name'] . '][weight]'] = $values['test_weight']; } $this->drupalPost('admin/structure/block', $edit, t('Save blocks')); foreach ($this->testBlocks as $values) { // Check if the region and weight settings changes have persisted. $this->assertOptionSelected( - 'edit-blocks-stark' . $values['settings']['machine_name'] . '-region', + 'edit-blocks-' . $values['settings']['machine_name'] . '-region', 'header', 'The block "' . $values['label'] . '" has the correct region assignment (header).' ); $this->assertOptionSelected( - 'edit-blocks-stark' . $values['settings']['machine_name'] . '-weight', + 'edit-blocks-' . $values['settings']['machine_name'] . '-weight', $values['test_weight'], 'The block "' . $values['label'] . '" has the correct weight assignment (' . $values['test_weight'] . ').' ); diff --git a/core/modules/block/lib/Drupal/block/Tests/NewDefaultThemeBlocksTest.php b/core/modules/block/lib/Drupal/block/Tests/NewDefaultThemeBlocksTest.php index f9a7792..ff554f4 100644 --- a/core/modules/block/lib/Drupal/block/Tests/NewDefaultThemeBlocksTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/NewDefaultThemeBlocksTest.php @@ -36,16 +36,21 @@ function testNewDefaultThemeBlocks() { $default_theme = config('system.theme')->get('default'); // Add several block instances. - $this->adminUser = $this->drupalCreateUser(array('administer blocks')); - $this->drupalLogin($this->adminUser); + $this->drupalLogin($this->drupalCreateUser(array('administer blocks'))); // Add two instances of the user login block. - $this->drupalPlaceBlock('user_login_block'); - $this->drupalPlaceBlock('user_login_block'); + $this->drupalPlaceBlock('user_login_block', array( + 'id' => $default_theme . '_' . strtolower($this->randomName(8)), + )); + $this->drupalPlaceBlock('user_login_block', array( + 'id' => $default_theme . '_' . strtolower($this->randomName(8)), + )); // Add an instance of a different block. - $this->drupalPlaceBlock('system_powered_by_block'); - $this->drupalLogout($this->adminUser); + $this->drupalPlaceBlock('system_powered_by_block', array( + 'id' => $default_theme . '_' . strtolower($this->randomName(8)), + )); + $this->drupalLogout(); // Enable a different theme. $new_theme = 'bartik'; @@ -56,30 +61,18 @@ function testNewDefaultThemeBlocks() { ->save(); // Ensure that the new theme has all the blocks as the previous default. - // @todo Replace the string manipulation below once the configuration - // system provides a method for extracting an ID in a given namespace. - $default_prefix = "block.block.$default_theme"; - $new_prefix = "block.block.$new_theme"; - $default_block_names = config_get_storage_names_with_prefix($default_prefix); - $new_blocks = array_flip(config_get_storage_names_with_prefix($new_prefix)); + $default_block_names = $this->container->get('entity.query')->get('block') + ->condition('theme', $default_theme) + ->execute(); + $new_blocks = $this->container->get('entity.query')->get('block') + ->condition('theme', $new_theme) + ->execute(); $this->assertTrue(count($default_block_names) == count($new_blocks), 'The new default theme has the same number of blocks as the previous theme.'); foreach ($default_block_names as $default_block_name) { - // Make sure the configuration object name is in the expected format. - if (strpos($default_block_name, $default_prefix) === 0) { - // Remove the matching block from the list of blocks in the new theme. - // E.g., if the old theme has block.block.stark.admin, - // unset block.block.bartik.admin. - $id = substr($default_block_name, (strlen($default_prefix) + 1)); - unset($new_blocks[$new_prefix . '.' . $id]); - } - else { - $this->fail(format_string( - '%block is not an expected block instance name.', - array( - '%block' => $default_block_name, - ) - )); - } + // Remove the matching block from the list of blocks in the new theme. + // E.g., if the old theme has block.block.stark_admin, + // unset block.block.bartik_admin. + unset($new_blocks[str_replace($default_theme . '_', $new_theme . '_', $default_block_name)]); } $this->assertTrue(empty($new_blocks), 'The new theme has exactly the same blocks as the previous default theme.'); } diff --git a/core/modules/block/lib/Drupal/block/Tests/Views/DisplayBlockTest.php b/core/modules/block/lib/Drupal/block/Tests/Views/DisplayBlockTest.php index ec3d500..483672c 100644 --- a/core/modules/block/lib/Drupal/block/Tests/Views/DisplayBlockTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/Views/DisplayBlockTest.php @@ -110,11 +110,11 @@ public function testViewsBlockForm() { $this->assertTrue(empty($elements), 'The label field is not found for Views blocks.'); // Test that that machine name field is hidden from display and has been // saved as expected from the default value. - $this->assertNoFieldById('edit-machine-name', 'stark.views_block__test_view_block_1', 'The machine name is hidden on the views block form.'); + $this->assertNoFieldById('edit-machine-name', 'views_block__test_view_block_1', 'The machine name is hidden on the views block form.'); // Save the block. $this->drupalPost(NULL, array(), t('Save block')); $storage = $this->container->get('plugin.manager.entity')->getStorageController('block'); - $block = $storage->load('stark.views_block__test_view_block_block_1'); + $block = $storage->load('views_block__test_view_block_block_1'); // This will only return a result if our new block has been created with the // expected machine name. $this->assertTrue(!empty($block), 'The expected block was loaded.'); @@ -122,7 +122,7 @@ public function testViewsBlockForm() { for ($i = 2; $i <= 3; $i++) { // Place the same block again and make sure we have a new ID. $this->drupalPost('admin/structure/block/add/views_block:test_view_block-block_1/' . $default_theme, array(), t('Save block')); - $block = $storage->load('stark.views_block__test_view_block_block_1_' . $i); + $block = $storage->load('views_block__test_view_block_block_1_' . $i); // This will only return a result if our new block has been created with the // expected machine name. $this->assertTrue(!empty($block), 'The expected block was loaded.'); diff --git a/core/modules/block/tests/modules/block_test/config/block.block.stark.test_block.yml b/core/modules/block/tests/modules/block_test/config/block.block.test_block.yml similarity index 91% rename from core/modules/block/tests/modules/block_test/config/block.block.stark.test_block.yml rename to core/modules/block/tests/modules/block_test/config/block.block.test_block.yml index e8b5ade..4b68aca 100644 --- a/core/modules/block/tests/modules/block_test/config/block.block.stark.test_block.yml +++ b/core/modules/block/tests/modules/block_test/config/block.block.test_block.yml @@ -1,4 +1,5 @@ -id: stark.test_block +id: test_block +theme: stark weight: '' status: '1' langcode: en diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index f0aa5fd..a6e58ab 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -348,7 +348,7 @@ protected function drupalCreateContentType(array $values = array()) { * @endcode * The following defaults are provided: * - label: Random string. - * - machine_name: Random string. + * - id: Random string. * - region: 'sidebar_first'. * - theme: The default theme. * - visibility: Empty array. @@ -360,21 +360,24 @@ protected function drupalCreateContentType(array $values = array()) { * Add support for creating custom block instances. */ protected function drupalPlaceBlock($plugin_id, array $settings = array()) { + // @todo Remove this. + if (isset($settings['machine_name'])) { + $settings['id'] = $settings['machine_name']; + } + $settings += array( 'plugin' => $plugin_id, 'region' => 'sidebar_first', - 'machine_name' => strtolower($this->randomName(8)), + 'id' => strtolower($this->randomName(8)), 'theme' => config('system.theme')->get('default'), 'label' => $this->randomName(8), 'visibility' => array(), ); - foreach (array('region', 'machine_name', 'theme', 'plugin', 'visibility') as $key) { + foreach (array('region', 'id', 'theme', 'plugin', 'visibility') as $key) { $values[$key] = $settings[$key]; unset($settings[$key]); } $values['settings'] = $settings; - // 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/system/lib/Drupal/system/Tests/System/AccessDeniedTest.php b/core/modules/system/lib/Drupal/system/Tests/System/AccessDeniedTest.php index eb4ba4a..32298d9 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/stark.login', $edit, t('Save block')); + $this->drupalPost('admin/structure/block/manage/login', $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 45f2efb..24dc839 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/BlockUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/BlockUpgradePathTest.php @@ -43,7 +43,7 @@ public function testBlockUpgradeTitleLength() { // Confirm that the custom block has been created, and title matches input. $settings = array( 'settings[label]' => $this->randomName(255), - 'machine_name' => strtolower($this->randomName(8)), + 'id' => strtolower($this->randomName(8)), 'region' => 'sidebar_first', ); $this->drupalPost('admin/structure/block/add/system_powered_by_block/' . config('system.theme')->get('default'), $settings, t('Save block')); @@ -52,7 +52,7 @@ public function testBlockUpgradeTitleLength() { // Try to add a block with a title over 255 characters. $settings = array( 'settings[label]' => $this->randomName(256), - 'machine_name' => strtolower($this->randomName(8)), + 'id' => strtolower($this->randomName(8)), 'region' => 'sidebar_first', ); $this->drupalPost('admin/structure/block/add/system_powered_by_block/' . config('system.theme')->get('default'), $settings, t('Save block')); diff --git a/core/modules/views/lib/Drupal/views/Plugin/Block/ViewsBlock.php b/core/modules/views/lib/Drupal/views/Plugin/Block/ViewsBlock.php index 8a0c919..604afe8 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/Block/ViewsBlock.php +++ b/core/modules/views/lib/Drupal/views/Plugin/Block/ViewsBlock.php @@ -10,6 +10,7 @@ use Drupal\block\BlockBase; use Drupal\Component\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Config\Entity\Query\Query; use Drupal\Core\Entity\EntityStorageControllerInterface; use Drupal\Component\Utility\Xss; @@ -114,21 +115,18 @@ protected function addContextualLinks(&$output, $block_type = 'block') { /** * Generates a views block instance ID. * - * @param \Drupal\Core\Entity\EntityStorageControllerInterface $manager - * The block storage controller. + * @param \Drupal\Core\Config\Entity\Query\Query $entity_query + * The entity query for a block. * * @return string * The new block instance ID. */ - public function generateBlockInstanceID(EntityStorageControllerInterface $manager) { + public function generateBlockInstanceID(Query $entity_query) { $this->view->setDisplay($this->displayID); $original_id = 'views_block__' . $this->view->storage->id() . '_' . $this->view->current_display; - // Get an array of block IDs without the theme prefix. - $block_ids = array_map(function ($block_id) { - $parts = explode('.', $block_id); - return end($parts); - }, array_keys($manager->loadMultiple())); + // Get an array of block IDs. + $block_ids = $entity_query->execute(); // Iterate through potential IDs until we get a new one. E.g. // 'views_block__MYVIEW_PAGE_1_2' diff --git a/core/modules/views/lib/Drupal/views/Tests/Plugin/ViewsBlockTest.php b/core/modules/views/lib/Drupal/views/Tests/Plugin/ViewsBlockTest.php index 759351a..be6c3b4 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Plugin/ViewsBlockTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/ViewsBlockTest.php @@ -62,25 +62,27 @@ public function testGenerateBlockInstanceID() { $views_block = new ViewsBlock(array(), $plugin_id, $plugin_definition); $storage_controller = $this->container->get('plugin.manager.entity')->getStorageController('block'); + $entity_query = $this->container->get('entity.query')->get('block'); // Generate a instance ID on a block without any instances. - $this->assertEqual($views_block->generateBlockInstanceID($storage_controller), 'views_block__test_view_block_block_1'); + $this->assertEqual($views_block->generateBlockInstanceID($entity_query), 'views_block__test_view_block_block_1'); $values = array( 'plugin' => $plugin_id, - 'id' => 'stark.views_block__test_view_block_block_1', + 'id' => 'views_block__test_view_block_block_1', + 'theme' => 'stark', 'module' => 'views', 'settings' => array( 'module' => 'views', ) ); $storage_controller->create($values)->save(); - $this->assertEqual($views_block->generateBlockInstanceID($storage_controller), 'views_block__test_view_block_block_1_2'); + $this->assertEqual($views_block->generateBlockInstanceID($entity_query), 'views_block__test_view_block_block_1_2'); // Add another one block instance and ensure the block instance went up. - $values['id'] = 'stark.views_block__test_view_block_block_1_2'; + $values['id'] = 'views_block__test_view_block_block_1_2'; $storage_controller->create($values)->save(); - $this->assertEqual($views_block->generateBlockInstanceID($storage_controller), 'views_block__test_view_block_block_1_3'); + $this->assertEqual($views_block->generateBlockInstanceID($entity_query), 'views_block__test_view_block_block_1_3'); } } diff --git a/core/modules/views/lib/Drupal/views/Tests/ViewTestBase.php b/core/modules/views/lib/Drupal/views/Tests/ViewTestBase.php index 5a00bd7..32285e5 100644 --- a/core/modules/views/lib/Drupal/views/Tests/ViewTestBase.php +++ b/core/modules/views/lib/Drupal/views/Tests/ViewTestBase.php @@ -263,9 +263,7 @@ protected function assertNoBlockAppears(Block $block) { * The result from the xpath query. */ protected function findBlockInstance(Block $block) { - $config_id = explode('.', $block->id()); - $machine_name = array_pop($config_id); - return $this->xpath('//div[@id = :id]', array(':id' => 'block-' . $machine_name)); + return $this->xpath('//div[@id = :id]', array(':id' => 'block-' . $block->id())); } /** diff --git a/core/modules/views/views.module b/core/modules/views/views.module index 5c4bb60..786c2f7 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -1667,15 +1667,15 @@ function views_cache_get($cid, $use_language = FALSE) { */ function views_form_block_form_alter(&$form, &$form_state) { // Ensure the block-form being altered is a Views block configuration form. - if (($form['settings']['module']['#value'] == 'views') && empty($form['machine_name']['#default_value'])) { - // Unset the machine_name provided by BlockFormController. - unset($form['machine_name']['#machine_name']['source']); + if (($form['settings']['module']['#value'] == 'views') && empty($form['id']['#default_value'])) { + // Unset the ID provided by BlockFormController. + unset($form['id']['#machine_name']['source']); // Load the Views plugin object using form_state array and create a - // block machine_name based on the View ID and View Display ID. + // block ID based on the View ID and View Display ID. $block_plugin = $form_state['controller']->getEntity()->getPlugin(); - // Override the Views block's machine_name by providing a default_value. - $form['machine_name']['#default_value'] = $block_plugin->generateBlockInstanceID(Drupal::entityManager()->getStorageController('block')); - // Prevent users from changing the auto-generated block machine_name. - $form['machine_name']['#access'] = FALSE; + // Override the Views block's ID by providing a default_value. + $form['id']['#default_value'] = $block_plugin->generateBlockInstanceID(Drupal::entityQuery('block')); + // Prevent users from changing the auto-generated block ID. + $form['id']['#access'] = FALSE; } } diff --git a/core/profiles/minimal/config/block.block.stark.admin.yml b/core/profiles/minimal/config/block.block.stark_admin.yml similarity index 92% rename from core/profiles/minimal/config/block.block.stark.admin.yml rename to core/profiles/minimal/config/block.block.stark_admin.yml index d67096f..b167665 100644 --- a/core/profiles/minimal/config/block.block.stark.admin.yml +++ b/core/profiles/minimal/config/block.block.stark_admin.yml @@ -1,4 +1,5 @@ -id: stark.admin +id: stark_admin +theme: stark weight: '1' status: '1' langcode: en diff --git a/core/profiles/minimal/config/block.block.stark.login.yml b/core/profiles/minimal/config/block.block.stark_login.yml similarity index 91% rename from core/profiles/minimal/config/block.block.stark.login.yml rename to core/profiles/minimal/config/block.block.stark_login.yml index b15e395..a727ff5 100644 --- a/core/profiles/minimal/config/block.block.stark.login.yml +++ b/core/profiles/minimal/config/block.block.stark_login.yml @@ -1,4 +1,5 @@ -id: stark.login +id: stark_login +theme: stark weight: '0' status: '1' langcode: en diff --git a/core/profiles/minimal/config/block.block.stark.tools.yml b/core/profiles/minimal/config/block.block.stark_tools.yml similarity index 91% rename from core/profiles/minimal/config/block.block.stark.tools.yml rename to core/profiles/minimal/config/block.block.stark_tools.yml index 6901d44..9110cd2 100644 --- a/core/profiles/minimal/config/block.block.stark.tools.yml +++ b/core/profiles/minimal/config/block.block.stark_tools.yml @@ -1,4 +1,5 @@ -id: stark.tools +id: stark_tools +theme: stark weight: '0' status: '1' langcode: en diff --git a/core/profiles/standard/config/block.block.bartik.breadcrumbs.yml b/core/profiles/standard/config/block.block.bartik_breadcrumbs.yml similarity index 90% rename from core/profiles/standard/config/block.block.bartik.breadcrumbs.yml rename to core/profiles/standard/config/block.block.bartik_breadcrumbs.yml index db92b96..282865b 100644 --- a/core/profiles/standard/config/block.block.bartik.breadcrumbs.yml +++ b/core/profiles/standard/config/block.block.bartik_breadcrumbs.yml @@ -1,4 +1,5 @@ -id: bartik.breadcrumbs +id: bartik_breadcrumbs +theme: bartik weight: '-5' status: '0' langcode: en diff --git a/core/profiles/standard/config/block.block.bartik.content.yml b/core/profiles/standard/config/block.block.bartik_content.yml similarity index 91% rename from core/profiles/standard/config/block.block.bartik.content.yml rename to core/profiles/standard/config/block.block.bartik_content.yml index 24b161c..e288270 100644 --- a/core/profiles/standard/config/block.block.bartik.content.yml +++ b/core/profiles/standard/config/block.block.bartik_content.yml @@ -1,4 +1,5 @@ -id: bartik.content +id: bartik_content +theme: bartik weight: '0' status: '1' langcode: en diff --git a/core/profiles/standard/config/block.block.bartik.footer.yml b/core/profiles/standard/config/block.block.bartik_footer.yml similarity index 91% rename from core/profiles/standard/config/block.block.bartik.footer.yml rename to core/profiles/standard/config/block.block.bartik_footer.yml index 65c77f0..94bade5 100644 --- a/core/profiles/standard/config/block.block.bartik.footer.yml +++ b/core/profiles/standard/config/block.block.bartik_footer.yml @@ -1,4 +1,5 @@ -id: bartik.footer +id: bartik_footer +theme: bartik weight: '0' status: '1' langcode: en diff --git a/core/profiles/standard/config/block.block.bartik.help.yml b/core/profiles/standard/config/block.block.bartik_help.yml similarity index 92% rename from core/profiles/standard/config/block.block.bartik.help.yml rename to core/profiles/standard/config/block.block.bartik_help.yml index 11f7ec6..72fe3e4 100644 --- a/core/profiles/standard/config/block.block.bartik.help.yml +++ b/core/profiles/standard/config/block.block.bartik_help.yml @@ -1,4 +1,5 @@ -id: bartik.help +id: bartik_help +theme: bartik weight: '0' status: '1' langcode: en diff --git a/core/profiles/standard/config/block.block.bartik.login.yml b/core/profiles/standard/config/block.block.bartik_login.yml similarity index 91% rename from core/profiles/standard/config/block.block.bartik.login.yml rename to core/profiles/standard/config/block.block.bartik_login.yml index 69e7f9b..b9c22f3 100644 --- a/core/profiles/standard/config/block.block.bartik.login.yml +++ b/core/profiles/standard/config/block.block.bartik_login.yml @@ -1,4 +1,5 @@ -id: bartik.login +id: bartik_login +theme: bartik weight: '0' status: '1' langcode: en diff --git a/core/profiles/standard/config/block.block.bartik.powered.yml b/core/profiles/standard/config/block.block.bartik_powered.yml similarity index 91% rename from core/profiles/standard/config/block.block.bartik.powered.yml rename to core/profiles/standard/config/block.block.bartik_powered.yml index a8de940..55e368c 100644 --- a/core/profiles/standard/config/block.block.bartik.powered.yml +++ b/core/profiles/standard/config/block.block.bartik_powered.yml @@ -1,4 +1,5 @@ -id: bartik.powered +id: bartik_powered +theme: bartik weight: '10' status: '1' langcode: en diff --git a/core/profiles/standard/config/block.block.bartik.search.yml b/core/profiles/standard/config/block.block.bartik_search.yml similarity index 91% rename from core/profiles/standard/config/block.block.bartik.search.yml rename to core/profiles/standard/config/block.block.bartik_search.yml index 18f6a7c..80c6857 100644 --- a/core/profiles/standard/config/block.block.bartik.search.yml +++ b/core/profiles/standard/config/block.block.bartik_search.yml @@ -1,4 +1,5 @@ -id: bartik.search +id: bartik_search +theme: bartik weight: '-1' status: '1' langcode: en diff --git a/core/profiles/standard/config/block.block.bartik.tools.yml b/core/profiles/standard/config/block.block.bartik_tools.yml similarity index 92% rename from core/profiles/standard/config/block.block.bartik.tools.yml rename to core/profiles/standard/config/block.block.bartik_tools.yml index 633e299..74b322e 100644 --- a/core/profiles/standard/config/block.block.bartik.tools.yml +++ b/core/profiles/standard/config/block.block.bartik_tools.yml @@ -1,4 +1,5 @@ -id: bartik.tools +id: bartik_tools +theme: bartik weight: '0' status: '1' langcode: en diff --git a/core/profiles/standard/config/block.block.seven.breadcrumbs.yml b/core/profiles/standard/config/block.block.seven_breadcrumbs.yml similarity index 90% rename from core/profiles/standard/config/block.block.seven.breadcrumbs.yml rename to core/profiles/standard/config/block.block.seven_breadcrumbs.yml index 6ca8962..3164cb7 100644 --- a/core/profiles/standard/config/block.block.seven.breadcrumbs.yml +++ b/core/profiles/standard/config/block.block.seven_breadcrumbs.yml @@ -1,4 +1,5 @@ -id: seven.breadcrumbs +id: seven_breadcrumbs +theme: seven weight: '-2' status: '0' langcode: en diff --git a/core/profiles/standard/config/block.block.seven.content.yml b/core/profiles/standard/config/block.block.seven_content.yml similarity index 91% rename from core/profiles/standard/config/block.block.seven.content.yml rename to core/profiles/standard/config/block.block.seven_content.yml index 1725800..908501e 100644 --- a/core/profiles/standard/config/block.block.seven.content.yml +++ b/core/profiles/standard/config/block.block.seven_content.yml @@ -1,4 +1,5 @@ -id: seven.content +id: seven_content +theme: seven weight: '0' status: '1' langcode: en diff --git a/core/profiles/standard/config/block.block.seven.help.yml b/core/profiles/standard/config/block.block.seven_help.yml similarity index 92% rename from core/profiles/standard/config/block.block.seven.help.yml rename to core/profiles/standard/config/block.block.seven_help.yml index 132ee45..0c41a8b 100644 --- a/core/profiles/standard/config/block.block.seven.help.yml +++ b/core/profiles/standard/config/block.block.seven_help.yml @@ -1,4 +1,5 @@ -id: seven.help +id: seven_help +theme: seven weight: '0' status: '1' langcode: en diff --git a/core/profiles/standard/config/block.block.seven.login.yml b/core/profiles/standard/config/block.block.seven_login.yml similarity index 92% rename from core/profiles/standard/config/block.block.seven.login.yml rename to core/profiles/standard/config/block.block.seven_login.yml index 8ec1661..5d7b69f 100644 --- a/core/profiles/standard/config/block.block.seven.login.yml +++ b/core/profiles/standard/config/block.block.seven_login.yml @@ -1,4 +1,5 @@ -id: seven.login +id: seven_login +theme: seven weight: '10' status: '1' langcode: en diff --git a/core/profiles/standard/lib/Drupal/standard/Tests/StandardTest.php b/core/profiles/standard/lib/Drupal/standard/Tests/StandardTest.php index fc21631..4ed4a3d 100644 --- a/core/profiles/standard/lib/Drupal/standard/Tests/StandardTest.php +++ b/core/profiles/standard/lib/Drupal/standard/Tests/StandardTest.php @@ -40,7 +40,7 @@ function testStandard() { $this->drupalGet('admin/structure/block/add/system_menu_block:menu-main/bartik'); $this->drupalPost(NULL, array( 'region' => 'sidebar_first', - 'machine_name' => 'main_navigation', + 'id' => 'main_navigation', ), t('Save block')); // Verify admin user can see the block. $this->drupalGet('');