diff --git a/core/modules/block/src/Controller/BlockListController.php b/core/modules/block/src/Controller/BlockListController.php index 273b192..b446799 100644 --- a/core/modules/block/src/Controller/BlockListController.php +++ b/core/modules/block/src/Controller/BlockListController.php @@ -72,18 +72,20 @@ public function listing($theme = NULL, Request $request = NULL) { */ public function layout($theme) { $headers = [ - ['data' => t('Block'), 'field' => 'name', 'sort' => 'asc'], - ['data' => t('Category'), 'field' => 'category'], - ['data' => t('Operations')], + ['data' => $this->t('Block'), 'field' => 'name'], + ['data' => $this->t('Category'), 'field' => 'category', 'sort' => 'asc'], + ['data' => $this->t('Operations')], ]; $rows = []; // Only add blocks which work without any available context. $definitions = $this->blockManager->getDefinitionsForContexts(); + // Do not display the 'broken' plugin in the UI. + unset($definitions['broken']); $order = tablesort_get_order($headers); $sort = tablesort_get_sort($headers); - if ($order['name'] == t('Category')) { + if ($order['name'] == $this->t('Category')) { // Order by category, and then by label. uasort($definitions, function ($a, $b) use ($sort) { if ($a['category'] != $b['category']) { @@ -99,9 +101,6 @@ public function layout($theme) { }); } - // Do not display the 'broken' plugin in the UI. - unset($definitions['broken']); - foreach ($definitions as $plugin_id => $plugin_definition) { $row = []; $row['title']['data'] = [ @@ -111,7 +110,7 @@ public function layout($theme) { ]; $row['category']['data'] = $plugin_definition['category']; $links['add'] = [ - 'title' => 'Add block', + 'title' => $this->t('Add block'), 'url' => Url::fromRoute('block.admin_add', ['plugin_id' => $plugin_id, 'theme' => $theme]), 'attributes' => [ 'class' => ['use-ajax'], @@ -130,14 +129,14 @@ public function layout($theme) { $build['filter'] = array( '#type' => 'search', - '#title' => t('Filter'), + '#title' =>$this->t('Filter'), '#title_display' => 'invisible', '#size' => 30, - '#placeholder' => t('Filter by block name'), + '#placeholder' =>$this->t('Filter by block name'), '#attributes' => [ 'class' => ['block-filter-text'], 'data-element' => '.block-add-table', - 'title' => t('Enter a part of the block name to filter by.'), + 'title' =>$this->t('Enter a part of the block name to filter by.'), ], ); @@ -145,7 +144,7 @@ public function layout($theme) { '#type' => 'table', '#header' => $headers, '#rows' => $rows, - '#empty' => t('No blocks available.'), + '#empty' =>$this->t('No blocks available.'), '#attributes' => [ 'class' => ['block-add-table'], ], diff --git a/core/modules/block/src/Tests/BlockUiTest.php b/core/modules/block/src/Tests/BlockUiTest.php index 025d8bf..254f5bd 100644 --- a/core/modules/block/src/Tests/BlockUiTest.php +++ b/core/modules/block/src/Tests/BlockUiTest.php @@ -132,23 +132,25 @@ public function testBlockAdminUiPage() { * Tests the block categories on the listing page. */ public function testCandidateBlockList() { + $pattern = '//tr[.//td/div[text()=:title] and .//td[text()=:category]]'; $arguments = array( ':title' => 'Display message', ':category' => 'Block test', ); - // Check if the block is on the list. + // Check if the block is listed. $this->drupalGet('admin/structure/block/list/classy/add'); - $elements = $this->xpath('//tr[.//td/div[text()=:title] and .//td[text()=:category]]', $arguments); + $elements = $this->xpath($pattern, $arguments); $this->assertTrue(!empty($elements), 'The test block appears in the category for its module.'); // Trigger the custom category addition in block_test_block_alter(). $this->container->get('state')->set('block_test_info_alter', TRUE); $this->container->get('plugin.manager.block')->clearCachedDefinitions(); + // Check if the block is listed with a custom category. $this->drupalGet('admin/structure/block/list/classy/add'); $arguments[':category'] = "Custom category"; - $elements = $this->xpath('//tr[.//td/div[text()=:title] and .//td[text()=:category]]', $arguments); + $elements = $this->xpath($pattern, $arguments); $this->assertTrue(!empty($elements), 'The test block appears in a custom category controlled by block_test_block_alter().'); } diff --git a/core/modules/block/src/Tests/Views/DisplayBlockTest.php b/core/modules/block/src/Tests/Views/DisplayBlockTest.php index d892bbe..1b34875 100644 --- a/core/modules/block/src/Tests/Views/DisplayBlockTest.php +++ b/core/modules/block/src/Tests/Views/DisplayBlockTest.php @@ -60,7 +60,7 @@ public function testBlockCategory() { $edit['block[style][row_plugin]'] = 'fields'; $this->drupalPostForm('admin/structure/views/add', $edit, t('Save and edit')); - $pattern = '//tr[.//td/div[text()=:text] and .//td[text()=:category] and .//td/div/div/ul/li/a[contains(@href, :href)]]'; + $pattern = './/td[text()=:category] and .//td/div/div/ul/li/a[contains(@href, :href)]]'; // Test that the block was given a default category corresponding to its // base table. @@ -70,7 +70,6 @@ public function testBlockCategory() { 'theme' => 'classy', )), ':category' => t('Lists (Views)'), - ':text' => $edit['label'], ); $this->drupalGet('admin/structure/block/list/classy/add'); $elements = $this->xpath($pattern, $arguments); @@ -106,7 +105,6 @@ public function testBlockCategory() { 'theme' => 'classy', )), ':category' => t('Lists (Views)'), - ':text' => $edit['label'], ); $elements = $this->xpath($pattern, $arguments); $this->assertTrue(!empty($elements), 'The first duplicated test block remains in the original category.'); @@ -117,7 +115,6 @@ public function testBlockCategory() { 'theme' => 'classy', )), ':category' => $category, - ':text' => $edit['label'], ); $elements = $this->xpath($pattern, $arguments); $this->assertTrue(!empty($elements), 'The second duplicated test block appears in the custom category.');