Loading core/modules/block/src/BlockListBuilder.php +10 −1 Original line number Diff line number Diff line Loading @@ -272,11 +272,20 @@ protected function buildBlocksForm() { $form[$entity_id]['#attributes']['class'][] = 'js-block-placed'; } $form[$entity_id]['info'] = [ '#plain_text' => $info['status'] ? $info['label'] : $this->t('@label (disabled)', ['@label' => $info['label']]), '#wrapper_attributes' => [ 'class' => ['block'], ], ]; // Ensure that the label is always rendered as plain text. Render // array #plain_text key is essentially treated same as @ placeholder // in translatable markup. if ($info['status']) { $form[$entity_id]['info']['#plain_text'] = $info['label']; } else { $form[$entity_id]['info']['#markup'] = $this->t('@label (disabled)', ['@label' => $info['label']]); } $form[$entity_id]['type'] = [ '#markup' => $info['category'], ]; Loading core/modules/block/tests/src/Functional/BlockTest.php +28 −0 Original line number Diff line number Diff line Loading @@ -588,4 +588,32 @@ public function testBlockUserRoleDelete() { $this->assertEquals([$role2->id() => $role2->id()], $block->getVisibility()['user_role']['roles']); } /** * Tests block title. */ public function testBlockTitle() { // Create a custom title for the block. $title = "This block's <b>great!</b>"; // Enable a standard block. $default_theme = $this->config('system.theme')->get('default'); $edit = [ 'id' => 'test', 'region' => 'sidebar_first', 'settings[label]' => $title, 'settings[label_display]' => TRUE, ]; // Set the block to be shown only to authenticated users. $edit['visibility[user_role][roles][' . RoleInterface::AUTHENTICATED_ID . ']'] = TRUE; $this->drupalGet('admin/structure/block/add/foo/' . $default_theme); $this->submitForm($edit, 'Save block'); // Ensure that the title is displayed as plain text. $elements = $this->xpath('//table/tbody/tr//td[contains(@class, "block")]'); $this->assertEquals($title, $elements[0]->getText()); $this->clickLink('Disable'); $elements = $this->xpath('//table/tbody/tr//td[contains(@class, "block")]'); $this->assertEquals("$title (disabled)", $elements[0]->getText()); } } Loading
core/modules/block/src/BlockListBuilder.php +10 −1 Original line number Diff line number Diff line Loading @@ -272,11 +272,20 @@ protected function buildBlocksForm() { $form[$entity_id]['#attributes']['class'][] = 'js-block-placed'; } $form[$entity_id]['info'] = [ '#plain_text' => $info['status'] ? $info['label'] : $this->t('@label (disabled)', ['@label' => $info['label']]), '#wrapper_attributes' => [ 'class' => ['block'], ], ]; // Ensure that the label is always rendered as plain text. Render // array #plain_text key is essentially treated same as @ placeholder // in translatable markup. if ($info['status']) { $form[$entity_id]['info']['#plain_text'] = $info['label']; } else { $form[$entity_id]['info']['#markup'] = $this->t('@label (disabled)', ['@label' => $info['label']]); } $form[$entity_id]['type'] = [ '#markup' => $info['category'], ]; Loading
core/modules/block/tests/src/Functional/BlockTest.php +28 −0 Original line number Diff line number Diff line Loading @@ -588,4 +588,32 @@ public function testBlockUserRoleDelete() { $this->assertEquals([$role2->id() => $role2->id()], $block->getVisibility()['user_role']['roles']); } /** * Tests block title. */ public function testBlockTitle() { // Create a custom title for the block. $title = "This block's <b>great!</b>"; // Enable a standard block. $default_theme = $this->config('system.theme')->get('default'); $edit = [ 'id' => 'test', 'region' => 'sidebar_first', 'settings[label]' => $title, 'settings[label_display]' => TRUE, ]; // Set the block to be shown only to authenticated users. $edit['visibility[user_role][roles][' . RoleInterface::AUTHENTICATED_ID . ']'] = TRUE; $this->drupalGet('admin/structure/block/add/foo/' . $default_theme); $this->submitForm($edit, 'Save block'); // Ensure that the title is displayed as plain text. $elements = $this->xpath('//table/tbody/tr//td[contains(@class, "block")]'); $this->assertEquals($title, $elements[0]->getText()); $this->clickLink('Disable'); $elements = $this->xpath('//table/tbody/tr//td[contains(@class, "block")]'); $this->assertEquals("$title (disabled)", $elements[0]->getText()); } }