diff --git a/core/modules/block/block.admin.inc b/core/modules/block/block.admin.inc index 4863a56..2259176 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. * @@ -190,7 +192,7 @@ function block_admin_display_form_submit($form, &$form_state) { * * Callback for usort() in block_admin_display_prepare_blocks(). */ -function _block_compare($a, $b) { +function _block_compare(Block $a, Block $b) { global $theme_key; // Theme should be set before calling this function, or the current theme @@ -262,6 +264,24 @@ function block_admin_add($plugin_id, $theme = NULL) { */ function block_admin_edit($entity_id) { $entity = entity_load('block', $entity_id); + + // 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)); + } + + // 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); } diff --git a/core/modules/block/block.module b/core/modules/block/block.module index be07557..3763584 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -131,7 +131,7 @@ function block_menu() { $items['admin/structure/block/manage/%'] = array( 'title' => 'Configure block', 'page callback' => 'block_admin_edit', - 'page arguments' => array(4, 5), + 'page arguments' => array(4), 'access arguments' => array('administer blocks'), 'file' => 'block.admin.inc', ); @@ -143,7 +143,7 @@ function block_menu() { $items['admin/structure/block/manage/%/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, @@ -317,7 +317,7 @@ function _block_get_renderable_region($list = array()) { if ($not_cacheable || in_array($block->get('cache'), array(DRUPAL_NO_CACHE, DRUPAL_CACHE_CUSTOM))) { // Non-cached blocks get built immediately. if ($block->access()) { - $build[$key] = entity_view($block, 'full'); + $build[$key] = entity_view($block, 'block'); } } else { @@ -476,7 +476,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()) { - $element += entity_view($block, 'full'); + $element += entity_view($block, 'block'); } return $element; } 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 3113bfe..37b11d4 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 @@ -72,6 +72,19 @@ public function blockForm($form, &$form_state) { } /** + * Overrides \Drupal\block\BlockBase::blockValidate(). + */ + public function blockValidate($form, &$form_state) { + $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.')); + } + } + + /** * Overrides \Drupal\block\BlockBase::blockSubmit(). */ public function blockSubmit($form, &$form_state) { diff --git a/core/modules/block/lib/Drupal/block/BlockFormController.php b/core/modules/block/lib/Drupal/block/BlockFormController.php index bf28b0f..8053279 100644 --- a/core/modules/block/lib/Drupal/block/BlockFormController.php +++ b/core/modules/block/lib/Drupal/block/BlockFormController.php @@ -29,25 +29,6 @@ public function form(array $form, array &$form_state, EntityInterface $entity) { '#value' => $entity->id(), ); - // 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)); - } - - // Get the block subject for the page title. - if ($label = $entity->label()) { - drupal_set_title(t("%label block in %theme", array('%label' => $label, '%theme' => $theme_title)), PASS_THROUGH); - } - $form['settings'] = array( '#weight' => -5, ); @@ -74,7 +55,7 @@ public function form(array $form, array &$form_state, EntityInterface $entity) { '#description' => t('Select the region where this block should be displayed.'), '#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. @@ -234,15 +215,6 @@ public function validate(array $form, array &$form_state) { $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']); $entity = $this->getEntity($form_state); if ($entity->isNew()) { diff --git a/core/modules/block/lib/Drupal/block/BlockRenderController.php b/core/modules/block/lib/Drupal/block/BlockRenderController.php index f5ae699..82134c6 100644 --- a/core/modules/block/lib/Drupal/block/BlockRenderController.php +++ b/core/modules/block/lib/Drupal/block/BlockRenderController.php @@ -37,9 +37,11 @@ public function buildContent(array $entities, array $displays, $view_mode, $lang * An array of defaults to add into the entity render array. */ protected function getBuildDefaults(EntityInterface $entity, $view_mode, $langcode) { - // @todo Added to facilitate the possibly bogus assertion in - // \Drupal\block\Tests\BlockTest::testCustomBlock(). - if ($view_mode != 'full') { + // @todo \Drupal\block\Tests\BlockTest::testCustomBlock() assuemes that a + // block can be rendered without any of its wrappers. To do so, it uses a + // custom view mode, and we choose to only add the wrappers on the default + // view mode, 'block'. + if ($view_mode != 'block') { return array(); } diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php index 274ddb2..ffc8d0f 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php @@ -117,8 +117,11 @@ public function testCustomBlock() { // 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 = entity_view($block, 'teaser'); + // 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.'); diff --git a/core/modules/user/lib/Drupal/user/Tests/UserBlocksTests.php b/core/modules/user/lib/Drupal/user/Tests/UserBlocksTests.php index cc96397..d4c3379 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserBlocksTests.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserBlocksTests.php @@ -99,7 +99,7 @@ function testWhosOnlineBlock() { $this->updateAccess($this->adminUser->uid, $inactive_time); // Test block output. - $content = entity_view($block, 'full'); + $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.');