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 f24106b..704517a 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 @@ -23,7 +23,7 @@ * "status" = TRUE, * "info" = "", * "body" = "", - * "format" = "" + * "format" = NULL * } * ) */ @@ -47,7 +47,7 @@ public function getConfig() { */ public function configure($form, &$form_state) { $form = parent::configure($form, $form_state); - $form['settings']['info'] = array( + $form['custom_block']['info'] = array( '#type' => 'textfield', '#title' => t('Block description'), '#required' => TRUE, @@ -55,9 +55,9 @@ public function configure($form, &$form_state) { '#description' => t('A brief description of your block. Used on the Blocks administration page.', array('@overview' => url('admin/structure/block'))), ); if (!empty($this->configuration['info'])) { - $form['settings']['info']['#disabled'] = TRUE; + $form['custom_block']['info']['#disabled'] = TRUE; } - $form['settings']['body'] = array( + $form['custom_block']['body'] = array( '#type' => 'text_format', '#title' => t('Block body'), '#default_value' => $this->configuration['body'], @@ -67,9 +67,9 @@ public function configure($form, &$form_state) { '#required' => TRUE, ); if (!empty($this->configuration['body'])) { - $form['settings']['body']['#disabled'] = TRUE; + $form['custom_block']['body']['#disabled'] = TRUE; } - $form['settings']['title']['#description'] = t('The title of the block as shown to the user.'); + $form['custom_block']['title']['#description'] = t('The title of the block as shown to the user.'); return $form; } diff --git a/core/modules/block/lib/Drupal/block/BlockBase.php b/core/modules/block/lib/Drupal/block/BlockBase.php index 0a02775..de96635 100644 --- a/core/modules/block/lib/Drupal/block/BlockBase.php +++ b/core/modules/block/lib/Drupal/block/BlockBase.php @@ -156,6 +156,9 @@ public function configureWrapper($form, &$form_state) { drupal_set_title(t("'%subject' block", array('%subject' => $subject)), PASS_THROUGH); } + $form['settings'] = array( + '#weight' => -5, + ); $form['settings']['machine_name'] = array( '#type' => 'textfield', '#title' => t('Block machine name'), @@ -184,6 +187,7 @@ public function configureWrapper($form, &$form_state) { '#title' => t('Region settings'), '#collapsible' => FALSE, '#description' => t('Specify in which themes and regions this block is displayed.'), + '#weight' => 5, ); $theme_default = variable_get('theme_default', 'stark'); @@ -216,6 +220,7 @@ public function configureWrapper($form, &$form_state) { $form['visibility_title'] = array( '#type' => 'item', '#title' => t('Visibility settings'), + '#weight' => 10, ); $form['visibility'] = array( '#type' => 'vertical_tabs', @@ -223,6 +228,7 @@ public function configureWrapper($form, &$form_state) { 'js' => array(drupal_get_path('module', 'block') . '/block.js'), ), '#tree' => TRUE, + '#weight' => 15, ); // Per-path visibility. diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php index 8686a25..d1c4233 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php @@ -2,14 +2,14 @@ /** * @file - * Definition of Drupal\block\Tests\BlockTest. + * Contains \Drupal\block\Tests\BlockTest. */ namespace Drupal\block\Tests; use Drupal\simpletest\WebTestBase; -class CustomBlockTest extends WebTestBase { +class BlockTest extends WebTestBase { /** * Modules to enable. @@ -35,10 +35,20 @@ function setUp() { // Use the test page as the front page. config('system.site')->set('page.front', 'test-page')->save(); + // Create Full HTML text format. + $full_html_format = array( + 'format' => 'full_html', + 'name' => 'Full HTML', + ); + $full_html_format = (object) $full_html_format; + filter_format_save($full_html_format); + $this->checkPermissions(array(), TRUE); + // Create and log in an administrative user having access to the Full HTML // text format. $this->adminUser = $this->drupalCreateUser(array( 'administer blocks', + filter_permission_name($full_html_format), 'access administration pages', )); $this->drupalLogin($this->adminUser); @@ -53,11 +63,137 @@ function setUp() { } /** + * Removes default blocks to avoid conflicts in the Block UI. + */ + 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(); + } + } + + /** + * Test creating custom block, moving it to a specific region and then deleting it. + */ + public function testCustomBlock() { + $default_theme = variable_get('theme_default', 'stark'); + $this->removeDefaultBlocks(); + + // Enable a second theme. + theme_enable(array('seven')); + + // Confirm that the add block link appears on block overview pages. + $this->drupalGet("admin/structure/block/list/block_plugin_ui:$default_theme/add"); + $this->assertLink(t('Add Custom Block')); + + // Confirm that hidden regions are not shown as options for block placement + // when adding a new block. + theme_enable(array('bartik')); + $themes = list_themes(); + $this->drupalGet('admin/structure/block/add'); + foreach ($themes as $key => $theme) { + if ($theme->status) { + foreach ($theme->info['regions_hidden'] as $hidden_region) { + $elements = $this->xpath('//select[@id=:id]//option[@value=:value]', array(':id' => 'edit-regions-' . $key, ':value' => $hidden_region)); + $this->assertFalse(isset($elements[0]), format_string('The hidden region @region is not available for @theme.', array('@region' => $hidden_region, '@theme' => $key))); + } + } + } + + // Add a new custom block by filling out the input form on the admin/structure/block/add page. + $info = strtolower($this->randomName(8)); + $custom_block['machine_name'] = $info; + $custom_block['info'] = $info; + $custom_block['title'] = $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 = $this->container->get('plugin.manager.block')->getInstance(array('config' => $plugin_id)); + $config = $block->getConfig(); + + // 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 whether the block can be moved to all available regions. + $custom_block['module'] = 'block'; + foreach ($this->regions as $region) { + $this->moveBlockToRegion($custom_block, $region); + } + + // 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"; + $this->assertLinkByHref("$config_block_id/configure", 0, 'Custom block configure link found.'); + $this->assertLinkByHref("$config_block_id/delete", 0, 'Custom block delete link found.'); + + // Set visibility only for authenticated users, to verify delete functionality. + $edit = array(); + $edit['visibility[role][roles][' . DRUPAL_AUTHENTICATED_RID . ']'] = TRUE; + $this->drupalPost("$config_block_id/configure", $edit, t('Save block')); + + // 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->drupalGet(NULL); + $this->assertNoText(t($custom_block['title']), 'Custom block no longer appears on page.'); + } + + /** + * Test creating custom block using Full HTML. + */ + public function testCustomBlockFormat() { + $default_theme = variable_get('theme_default', 'stark'); + $this->removeDefaultBlocks(); + + // Add a new custom block by filling out the input form on the admin/structure/block/add page. + $info = $this->randomName(8); + $custom_block['machine_name'] = $info; + $custom_block['info'] = $info; + $custom_block['title'] = $this->randomName(8); + $custom_block['body[value]'] = '