Problem/Motivation

If block instances can be removed from /structure/block-layout with the 'remove' action we should expose that as a contextual link as well.

A default block

A custom block

Proposed resolution

Add the "remove" contextual link to blocks.

Remaining tasks

Write patch

User interface changes

All blocks get a "remove" contextual link.

API changes

-

Data model changes

-

CommentFileSizeAuthor
#46 Screen Shot 2021-05-20 at 2.50.01 PM.png68.55 KBwebchick
#46 Screen Shot 2021-05-20 at 2.48.40 PM.png26.51 KBwebchick
#37 interdiff-2839558-34-37.txt1.81 KBmohit_aghera
#37 2839558-block_remove-37.patch5.38 KBmohit_aghera
#34 interdiff-2839558-30-34.txt3.69 KBmohit_aghera
#34 2839558-block_remove-34.patch4.97 KBmohit_aghera
#30 interdiff-2839558-20-30.txt5.76 KBmohit_aghera
#30 2839558-block_remove-30.patch5 KBmohit_aghera
#28 After-patch.png209.17 KBmeghasharma
#28 Before-patch.png204.98 KBmeghasharma
#27 after-patch-removelink.png257.99 KBMadhu kumar
#26 2839558_after.gif4.68 MBhinal05
#26 2839558_before.gif4.91 MBhinal05
#25 Screenshot 2021-03-19 at 10.49.34 AM.png90.66 KBvakulrai
#24 2839558-after.gif5.5 MBAbhijith S
#24 2839558-before.png5.26 KBAbhijith S
#23 Screenshot 2021-03-19 at 9.54.31 AM.png80.62 KBmohit_aghera
#22 after-patch.png74.07 KBdjsagar
#21 block_remove.mkv440.51 KBguilhermevp
#20 interdiff-2839558-block_remove-6-20.txt3.22 KBmohit_aghera
#20 2839558-block_remove-20.patch4.13 KBmohit_aghera
#6 2839558-block_remove-6.patch921 bytestim.plunkett
Screen Shot 2016-12-27 at 11.13.14 AM.png25.85 KBtkoleary
Screen Shot 2016-12-27 at 11.17.40 AM.png32.64 KBtkoleary

Issue fork drupal-2839558

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tkoleary created an issue. See original summary.

tkoleary’s picture

Issue summary: View changes
tim.plunkett’s picture

I have to assume that you have #2826728: Block layout action removes instance, but contextual link deletes all instances. running locally, because there are no "Remove" contextual links for blocks yet.

In HEAD it says "Delete" because only custom blocks can be deleted.

I think this and that other issue should be combined into a feature request for "Add a 'Remove' contextual link to placed blocks" or similar.

tkoleary’s picture

Issue summary: View changes
tkoleary’s picture

Title: Default blocks do not have a "remove" contextual link » Blocks do not have a "remove" contextual link
tim.plunkett’s picture

Status: Needs review » Needs work

The last submitted patch, 6: 2839558-block_remove-6.patch, failed testing.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Chris Charlton’s picture

Too bad this little guy got stalled. Consistency is a platform asset. :)

tim.plunkett’s picture

Feel free to review the patch!

Chris Charlton’s picture

I did. It's pretty straightforward. It failed tests, so I assume that's a blocker? Or no?

tim.plunkett’s picture

Issue tags: +Needs tests

It failed tests because the tests were brittle. Those can be fixed.
But did it work when you tried it out?

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

mohit_aghera’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
4.13 KB
3.22 KB

@tim.plunkett
This patch is working as expected and adding "Remove" contextual link for the blocks.

I've also added additional test cases where we are rendering static blocks like "powered by Drupal".
That block has two links as it is static.

guilhermevp’s picture

FileSize
440.51 KB

Patch works as intended. Adding video evidence.

djsagar’s picture

Status: Needs review » Needs work
FileSize
74.07 KB

Hi @mohit_aghera,

I applied your patch but not adding "Remove" contextual link for the blocks.

i created custom block and placed but didn't find any changes.

please review the attachment.

Thanks!

mohit_aghera’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
80.62 KB

@djsagar
I am able to see the links on the blocks created via "block_content"
Can you please share the exact steps?

Abhijith S’s picture

FileSize
5.26 KB
5.5 MB

Applied patch #20 and it works fine.

Before patch:
before

After patch:
after

RTBC +1

vakulrai’s picture

I verified The patch #20 and its working as expected. #22 I think the problem you are facing is because of the block cache, try clearing it once.
Added a screenshot.
Thanks

hinal05’s picture

FileSize
4.91 MB
4.68 MB

Applied patch #20 and it's working fine for me.

For #22 comment, I think this issue is replicated after applied patch, old block not adding "Remove" link. We need to add new custom block then it will replicating.

You can check this thing in attached GIF.

Madhu kumar’s picture

FileSize
257.99 KB

patch #20 applied cleanly and working as expected , and have a "remove" contextual link ,screenshot added for reference

meghasharma’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
204.98 KB
209.17 KB

Patch #20 applied cleanly and it is working well.
Reviewed the #26 and #27 screenshots, Looks good
screenshot for reference.
Added "remove" action contextual link
Marking as RTBC

tim.plunkett’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/block/block.links.contextual.yml
    @@ -2,3 +2,8 @@ block_configure:
    +  title: 'Remove'
    
    +++ b/core/modules/block/block.routing.yml
    @@ -13,7 +13,7 @@ entity.block.delete_form:
    +    _title: 'Remove block'
    

    Similar to the "Configure block" contextual link (and to the "Remove block" one already in Layout Builder), I think both of these should be "Remove block"

  2. +++ b/core/modules/block/tests/src/Functional/Views/DisplayBlockTest.php
    @@ -394,8 +394,23 @@ public function testBlockContextualLinks() {
    +    $id_token = Crypt::hmacBase64($id, Settings::getHashSalt() . $this->container->get('private_key')->get());
    ...
    +    $url = '/contextual/render?_format=json,destination=/';
    +    $this->getSession()->getDriver()->getClient()->request('POST', $url, $post);
    ...
    +    $this->assertSame('<ul class="contextual-links"><li class="block-configure"><a href="/admin/structure/block/manage/' . $block_id . '">Configure block</a></li><li class="block-remove"><a href="/admin/structure/block/manage/' . $block_id . '/delete">Remove</a></li></ul>', $json[$id]);
    

    This is very trick test code. Could this instead be added to a FunctionalJavascript test and use a normal assertion?

mohit_aghera’s picture

Status: Needs work » Needs review
FileSize
5 KB
5.76 KB

Thanks @tim.plunkett
I've updated the title and test cases so that it uses FunctionalJavascript tests.

mohit_aghera’s picture

Status: Needs review » Needs work

The last submitted patch, 30: 2839558-block_remove-30.patch, failed testing. View results

mohit_aghera’s picture

Assigned: Unassigned » mohit_aghera
mohit_aghera’s picture

Status: Needs work » Needs review
FileSize
4.97 KB
3.69 KB

@tim.plunkett
I've refactored tests to separate classes.
Contextual links test in BlockFilterTest was failing for the ClaroBlockFilterTest tests.
The reason is, for the claro theme, we are disabling contextual links for a few blocks.

Update
Tests are passing on local.
Here is the quick output.

ohit@drupal8-web:/var/www/html$ vendor/bin/phpunit -c core --filter=BlockContextualLinksTest
PHPUnit 8.5.13 by Sebastian Bergmann and contributors.

Testing
.                                                                   1 / 1 (100%)

Time: 45.5 seconds, Memory: 808.00 MB

OK (1 test, 3 assertions)

Triggering the test build again.

Status: Needs review » Needs work

The last submitted patch, 34: 2839558-block_remove-34.patch, failed testing. View results

tim.plunkett’s picture

+++ b/core/modules/block/tests/src/FunctionalJavascript/BlockContextualLinksTest.php
@@ -0,0 +1,54 @@
+    $this->assertSession()->responseContains('<ul class="contextual-links" hidden=""><li><a href="' . base_path() . 'admin/structure/block/manage/' . $this->blockId . '?destination=/user/' . $this->rootUser->id() . '">Configure block</a></li><li><a href="' . base_path() . 'admin/structure/block/manage/' . $this->blockId . '/delete?destination=/user/' . $this->rootUser->id() . '">Remove block</a></li></ul>');

This needs to wait for the contextual links to render before asserting. It's passing locally for you because you are running a single test. The testbot runs 15 test concurrently, so the gap between page render and contextual links render is longer.

Something like

$this->assertSession()->waitForElement('css', '.contextual button');

(selector might need adjusting)

Additionally, can we assert that the page contains what we want without needing all of the markup hardcoded in the assertion?

mohit_aghera’s picture

Assigned: mohit_aghera » Unassigned
Status: Needs work » Needs review
FileSize
5.38 KB
1.81 KB

Updating the suggestions mentioned in #36

Status: Needs review » Needs work

The last submitted patch, 37: 2839558-block_remove-37.patch, failed testing. View results

benjifisher’s picture

Please do not ask the testbot to try again until #3207086: [HEAD BROKEN] Consistent failure in MonthDatePluginTest is fixed.

alexpott’s picture

Status: Needs work » Reviewed & tested by the community
larowlan’s picture

Category: Bug report » Feature request

This feels like a feature request to me, and @tim.plunkett said the same in #3

larowlan’s picture

Issue tags: +Bug Smash Initiative

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 37: 2839558-block_remove-37.patch, failed testing. View results

catch’s picture

Status: Needs work » Reviewed & tested by the community

Restoring status after HEAD was broken.

webchick’s picture

Status: Reviewed & tested by the community » Needs work
FileSize
26.51 KB
68.55 KB

Code looks straight-forward enough! Here's a review from the UX side.

The screenshot in the issue summary shows "Remove" as the last option, and that also tracks with what I'd expect, since it is very likely to be the least used option.

And yet... Here it is in the middle, on a menu block?

Edit Menu is last in list, not Remove block

Upon clicking "Remove block," it busts you out of the front-end into a standalone confirm page using the admin theme:

Standalone admin confirm page

This is at odds with what Quick Edit is intending to do, which is keep all of your admin functions on the front-end. Is there a reason a dialog wasn't used here for the confirm box instead?

And finally, the wording there is super spooky... It makes it sound like you're removing the User account menu block from the block system entirely, but you're really only removing its placement from this one region. And it can easily be undone. Do we have options to rephrase here? For example:

"Are you sure you want to remove the block User account menu from the Secondary menu region?
This will remove the block placement. You will need to place it again in order to undo this action."

tim.plunkett’s picture

Thanks for the review! There are three points of feedback: order of the links, redirecting to admin theme, and the wording of the form.

1)
Contextual links have a weight property, but they also have a group property. The weight only affects their order within their group.
The "Configure block" and new "Remove block" links have a group of block.
The "Edit menu" link has a group of menu.
This means that no matter how high of a weight we set for the new link, it will still be below the "Edit menu" link.
In theory we could implement hook_contextual_links_view_alter() to move it to the bottom... But that's really heavy-handed.

2)
Currently all of the contextual links redirect to a page in the admin theme.
The Settings Tray module was working to stop doing this, but it's
a) not installed by default
b) does not fix these links to use it

We don't use dialogs for any of this right now.

I opened #3215209: After clicking "Remove block" contextual link, open form in off-canvas dialog as a follow-up for this

3)
I changed the wording of the form to match your suggestion. That's the only code change currently...

NOTE: I switched from patches to a new MR!

phenaproxima’s picture

Status: Needs review » Reviewed & tested by the community

Took a look at this and I think that @webchick's feedback has been addressed. Restoring RTBC!

  • webchick committed adb24cf on 9.3.x
    Issue #2839558 by tim.plunkett, mohit_aghera, tkoleary, webchick,...
webchick’s picture

Status: Reviewed & tested by the community » Fixed

Tim walked me through this again today and lookin' good! All feedback addressed.

Committed and pushed to 9.3.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.