Issue #2839558 by tim.plunkett, mohit_aghera, tkoleary, webchick, guilhermevp: Blocks do not have a "remove" contextual link
parent
af5f071327
commit
adb24cf8a8
|
@ -2,3 +2,8 @@ block_configure:
|
|||
title: 'Configure block'
|
||||
route_name: 'entity.block.edit_form'
|
||||
group: 'block'
|
||||
|
||||
block_remove:
|
||||
title: 'Remove block'
|
||||
route_name: 'entity.block.delete_form'
|
||||
group: 'block'
|
||||
|
|
|
@ -13,7 +13,7 @@ entity.block.delete_form:
|
|||
path: '/admin/structure/block/manage/{block}/delete'
|
||||
defaults:
|
||||
_entity_form: 'block.delete'
|
||||
_title: 'Delete block'
|
||||
_title: 'Remove block'
|
||||
requirements:
|
||||
_permission: 'administer blocks'
|
||||
|
||||
|
|
|
@ -30,9 +30,21 @@ class BlockDeleteForm extends EntityDeleteForm {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getQuestion() {
|
||||
return $this->t('Are you sure you want to remove the @entity-type %label?', [
|
||||
'@entity-type' => $this->getEntity()->getEntityType()->getSingularLabel(),
|
||||
'%label' => $this->getEntity()->label(),
|
||||
$entity = $this->getEntity();
|
||||
$regions = $this->systemRegionList($entity->getTheme(), REGIONS_VISIBLE);
|
||||
return $this->t('Are you sure you want to remove the @entity-type %label from the %region region?', [
|
||||
'@entity-type' => $entity->getEntityType()->getSingularLabel(),
|
||||
'%label' => $entity->label(),
|
||||
'%region' => $regions[$entity->getRegion()],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDescription() {
|
||||
return $this->t('This will remove the block placement. You will need to <a href=":url">place it again</a> in order to undo this action.', [
|
||||
':url' => Url::fromRoute('block.admin_display_theme', ['theme' => $this->getEntity()->getTheme()])->toString(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -41,10 +53,19 @@ class BlockDeleteForm extends EntityDeleteForm {
|
|||
*/
|
||||
protected function getDeletionMessage() {
|
||||
$entity = $this->getEntity();
|
||||
return $this->t('The @entity-type %label has been removed.', [
|
||||
$regions = $this->systemRegionList($entity->getTheme(), REGIONS_VISIBLE);
|
||||
return $this->t('The @entity-type %label has been removed from the %region region.', [
|
||||
'@entity-type' => $entity->getEntityType()->getSingularLabel(),
|
||||
'%label' => $entity->label(),
|
||||
'%region' => $regions[$entity->getRegion()],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps system_region_list().
|
||||
*/
|
||||
protected function systemRegionList($theme, $show = REGIONS_ALL) {
|
||||
return system_region_list($theme, $show);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -244,17 +244,17 @@ class BlockTest extends BlockTestBase {
|
|||
// Test deleting the block from the edit form.
|
||||
$this->drupalGet('admin/structure/block/manage/' . $block['id']);
|
||||
$this->clickLink(t('Remove block'));
|
||||
$this->assertRaw(t('Are you sure you want to remove the block @name?', ['@name' => $block['settings[label]']]));
|
||||
$this->assertRaw(t('Are you sure you want to remove the block @name from the @region region?', ['@name' => $block['settings[label]'], '@region' => 'Footer']));
|
||||
$this->submitForm([], 'Remove');
|
||||
$this->assertRaw(t('The block %name has been removed.', ['%name' => $block['settings[label]']]));
|
||||
$this->assertRaw(t('The block %name has been removed from the %region region.', ['%name' => $block['settings[label]'], '%region' => 'Footer']));
|
||||
|
||||
// Test deleting a block via "Configure block" link.
|
||||
$block = $this->drupalPlaceBlock('system_powered_by_block');
|
||||
$this->drupalGet('admin/structure/block/manage/' . $block->id(), ['query' => ['destination' => 'admin']]);
|
||||
$this->clickLink(t('Remove block'));
|
||||
$this->assertRaw(t('Are you sure you want to remove the block @name?', ['@name' => $block->label()]));
|
||||
$this->assertRaw(t('Are you sure you want to remove the block @name from the @region region?', ['@name' => $block->label(), '@region' => 'Left sidebar']));
|
||||
$this->submitForm([], 'Remove');
|
||||
$this->assertRaw(t('The block %name has been removed.', ['%name' => $block->label()]));
|
||||
$this->assertRaw(t('The block %name has been removed from the %region region.', ['%name' => $block->label(), '%region' => 'Left sidebar']));
|
||||
$this->assertSession()->addressEquals('admin');
|
||||
$this->assertNoRaw($block->id());
|
||||
}
|
||||
|
|
|
@ -397,8 +397,8 @@ class DisplayBlockTest extends ViewTestBase {
|
|||
$this->getSession()->getDriver()->getClient()->request('POST', $url, $post);
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
$json = Json::decode($this->getSession()->getPage()->getContent());
|
||||
$this->assertSame('<ul class="contextual-links"><li class="block-configure"><a href="' . base_path() . 'admin/structure/block/manage/' . $block->id() . '">Configure block</a></li><li class="entityviewedit-form"><a href="' . base_path() . 'admin/structure/views/view/test_view_block/edit/block_1">Edit view</a></li></ul>', $json[$id]);
|
||||
$this->assertSame('<ul class="contextual-links"><li class="block-configure"><a href="' . base_path() . 'admin/structure/block/manage/' . $cached_block->id() . '">Configure block</a></li><li class="entityviewedit-form"><a href="' . base_path() . 'admin/structure/views/view/test_view_block/edit/block_1">Edit view</a></li></ul>', $json[$cached_id]);
|
||||
$this->assertSame('<ul class="contextual-links"><li class="block-configure"><a href="' . base_path() . 'admin/structure/block/manage/' . $block->id() . '">Configure block</a></li><li class="block-remove"><a href="' . base_path() . 'admin/structure/block/manage/' . $block->id() . '/delete">Remove block</a></li><li class="entityviewedit-form"><a href="' . base_path() . 'admin/structure/views/view/test_view_block/edit/block_1">Edit view</a></li></ul>', $json[$id]);
|
||||
$this->assertSame('<ul class="contextual-links"><li class="block-configure"><a href="' . base_path() . 'admin/structure/block/manage/' . $cached_block->id() . '">Configure block</a></li><li class="block-remove"><a href="' . base_path() . 'admin/structure/block/manage/' . $cached_block->id() . '/delete">Remove block</a></li><li class="entityviewedit-form"><a href="' . base_path() . 'admin/structure/views/view/test_view_block/edit/block_1">Edit view</a></li></ul>', $json[$cached_id]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block\FunctionalJavascript;
|
||||
|
||||
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
|
||||
|
||||
/**
|
||||
* Tests the contextual links added while rendering the block.
|
||||
*
|
||||
* @group block
|
||||
*/
|
||||
class BlockContextualLinksTest extends WebDriverTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $modules = ['user', 'block', 'contextual'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $defaultTheme = 'stark';
|
||||
|
||||
/**
|
||||
* Block id of the block.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $blockId;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->blockId = $this->defaultTheme . '_powered';
|
||||
$this->placeBlock('system_powered_by_block', [
|
||||
'id' => $this->blockId,
|
||||
'region' => 'content',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to ensure that remove contextual link is present in the block.
|
||||
*/
|
||||
public function testBlockContextualRemoveLinks() {
|
||||
// Ensure that contextual filter links are visible on the page.
|
||||
$this->drupalLogin($this->rootUser);
|
||||
$this->drupalGet('<front>');
|
||||
$contextual_id = "[data-contextual-id^='block:block=$this->blockId:langcode=en']";
|
||||
$this->assertSession()->waitForElement('css', "$contextual_id .contextual-links");
|
||||
|
||||
$expected_configure_block_link = base_path() . 'admin/structure/block/manage/' . $this->blockId;
|
||||
$actual_configure_block_link = parse_url($this->getSession()->getPage()->findLink('Configure block')->getAttribute('href'));
|
||||
$this->assertEquals($expected_configure_block_link, $actual_configure_block_link['path']);
|
||||
|
||||
$expected_remove_block_link = base_path() . 'admin/structure/block/manage/' . $this->blockId . '/delete';
|
||||
$actual_remove_block_link = parse_url($this->getSession()->getPage()->findLink('Remove block')->getAttribute('href'));
|
||||
$this->assertEquals($expected_remove_block_link, $actual_remove_block_link['path']);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue