Provide helpful editing links on "admin/structure/block" for deriver blocks (menu, views, block content, etc.)

Created on 29 March 2013, about 11 years ago
Updated 20 May 2024, about 1 month ago

Problem/Motivation

As raised on #1938062-54: Convert the recent_comments block to a view β†’ it might be really useful to provide additional dropdown links
on the block overview page.

Some examples could be an edit link for a menu, and edit link for the view, the aggregator feed configuration etc.

Proposed resolution

Use hook_entity_operation() to add links for editing menus, views and content blocks to blocks.

Remaining tasks





Review
Commit

User interface changes

Before

After

API changes

None

Data model changes

None

Original report by @dawehner β†’

As raised on #1938062-54: Convert the recent_comments block to a view β†’ it might be really useful to provide additional dropdown links
on the block overview page.

Some examples could be an edit link for a menu, and edit link for the view, the aggregator feed configuration etc.

πŸ“Œ Task
Status

Fixed

Version

10.3 ✨

Component
BlockΒ  β†’

Last updated 2 days ago

Created by

πŸ‡©πŸ‡ͺGermany dawehner

Live updates comments and jobs are added and updated live.
  • Usability

    Makes Drupal easier to use. Preferred over UX, D7UX, etc.

  • VDC

    Related to the Views in Drupal Core initiative.

  • Blocks-Layouts

    Blocks and Layouts Initiative. See the #2811175 Add layouts to Drupal issue.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Status changed to Needs work over 1 year ago
  • πŸ‡¬πŸ‡§United Kingdom joachim

    @smustgrave I'm on a train and without access to Slack, so in response to your comment there:

    The latest patch is adding a method to block plugins, and calling it in on all block plugins:


    + public function getOperationLinks(): array {
    + $plugin = $this->getPlugin();
    + if (method_exists($plugin, 'getOperationLinks')) {
    + return $plugin->getOperationLinks();
    + }
    + return [];
    + }

    Therefore, BlockPluginInterface must add this method.

    Previous patches defined a new interface for block plugins to implement optionally:

    > If we add getOperationsLinks to BlockBase

    which is fine, but BlockPluginInterface must still add this method because that is part of the API we are expecting block plugins to have.

    There seems to be some confusion on this issue about the entity and the plugin. Both are called 'block' which doesn't help. There are two totally separate class/interface hierarchies in play here:

    - the block entity, which inherits from ConfigEntityBase, implements BlockInterface. This holds the configuration the admin user enters.
    - the block plugin, which inherits from BlockBase, implements BlockPluginInterface. This holds the machinery for outputting the block.

  • πŸ‡¬πŸ‡§United Kingdom joachim

    Oh wait, it's using method_exists($plugin, 'getOperationLinks').

    Let's not do that though -- it's ugly. We should add the method to the block interface.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Then won't I have to update all block plugins now. They all seem to complain about the missing function if I add to BlockPluginInterface

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    No, just add an empty implementation to BlockBase, all blocks are expected to extend from it

  • Status changed to Needs review over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Like this?

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Had to add a stub to Broke.php.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    All green!

  • Status changed to Needs work over 1 year ago
  • πŸ‡¬πŸ‡§United Kingdom joachim
    1. +++ b/core/lib/Drupal/Core/Block/Plugin/Block/Broken.php
      @@ -93,4 +93,8 @@ protected function brokenMessage() {
      +  public function getOperationLinks(): array {
      +    return [];
      

      This needs an inherit doc. I'm surprised the code checking didn't complain about it!

    2. +++ b/core/modules/block/src/Entity/Block.php
      @@ -354,4 +354,15 @@ public function preSave(EntityStorageInterface $storage) {
      +    if (method_exists($plugin, 'getOperationLinks')) {
      

      We don't need to check the method exists, since it's on the block plugin interface. Every block plugin *must* implement this.

  • Status changed to Needs review over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Fixed points in #285

    Think the issue summary is fine but am working on CR updates

  • Status changed to RTBC over 1 year ago
  • πŸ‡¬πŸ‡§United Kingdom joachim

    Yay! I think this is ready!

    I don't think we need this CR:

    > SystemMenuBlock uses ModuleHandlerInterface and AccountInterface

    The BC policy says:

    > Particular plugins, whether class based or yaml based, should not be considered part of the public API. References to plugin IDs and settings in default configuration can be relied upon however.

  • Status changed to Needs work over 1 year ago
  • πŸ‡³πŸ‡ΏNew Zealand quietone New Zealand

    Unfortunately, the patch is not passing the checks.

  • Status changed to Needs review over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave
  • Status changed to Needs work over 1 year ago
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    First up, I apologize in advance for asking some awkward questions here. But I'm concerned about the implicit dependencies this adds between the system module and the menu UI module, as well as the views module and the views UI module.

    But first some minor comments

    1. +++ b/core/modules/block/src/BlockListBuilder.php
      @@ -365,6 +365,25 @@ public function getDefaultOperations(EntityInterface $entity) {
      +        $operation_extra['url']->setOption('query', ['destination' => 'admin/structure/block']);
      

      Per review above from @andypost and myself, I think this should use the existing ::ensureDestination method on this class

    2. +++ b/core/modules/block_content/src/Plugin/Block/BlockContentBlock.php
      @@ -213,4 +213,26 @@ protected function getEntity() {
      +        // Using this weight so this option appears at the top.
      

      This comment doesn't match the code, 50 would put it at the bottom.

    3. +++ b/core/modules/block_content/tests/src/Kernel/BlockContentTest.php
      @@ -0,0 +1,78 @@
      +    $this->setUpCurrentUser(['uid' => 1], ['edit any spiffy block content']);
      ...
      +    // At this point, we are logged in as an admin, so the user does
      +    // have the "administer block" permission.
      

      I don't think we should test this with user 1. So perhaps create it with a UID > 1

      User 1 typically bypasses access checks

      It will require granting the 'administer block' permission too, but then we're getting closer to a real test

    4. +++ b/core/modules/system/src/Plugin/Block/SystemMenuBlock.php
      @@ -232,4 +251,26 @@ public function getCacheContexts() {
      +      $menu = Menu::load($menu_name);
      +      if ($menu->access('edit')) {
      +        $links['menu-edit'] = [
      +          'title' => $this->t('Edit menu'),
      +          'url' => Url::fromRoute('entity.menu.edit_form', ['menu' => $menu_name]),
      +          'weight' => 50,
      

      Ok, brace yourself, this is where I get annoying.

      I'm not convinced system module should know about the menu UI module.

      And perhaps that suggests we're missing an API here.

      For example, let's say module A wants to modify the operation links of module B. e.g. in this case menu_ui would want to edit the operation links of system module.

      But then when you think about it, we already have a hook for adding and altering operation links - that's hook_entity_operation and hook_entity_operation_alter

      So if menu_ui cares about an operation for a block provided by system module, it should handle it itself, not the other way around.

      So I think this change should be reversed, and menu_ui module should implement one of those hooks, probably the first one and add this edit link from there.

    5. +++ b/core/modules/views/src/Plugin/Block/ViewsBlockBase.php
      @@ -233,4 +245,25 @@ public function getViewExecutable() {
      +    if ($this->moduleHandler->moduleExists('views_ui') && $view->storage->access('edit')) {
      +      $links['view-edit'] = [
      +        'title' => $this->t('Edit view'),
      +        'url' => Url::fromRoute('entity.view.edit_display_form', [
      +          'view' => $view->id(),
      +          'display_id' => $display_id,
      +        ]),
      +        'weight' => 50,
      

      And the same comment here re views ui / views module and the existing hook

    So yeah, those last two points are annoying, and sorry they're coming at comment #290. But one good thing is, the test already exists, so the impact shouldn't be as great.

    The added bonus of that is we don't need any API changes for those two block plugins, which are commonly extended (yes they're internal, but in reality they do get extended a lot).

    Thanks again for keeping this moving @smustgrave, and once again sorry for pushing back this late

  • πŸ‡―πŸ‡΄Jordan Mutasim Al-Shoura

    I have updated patch #289 and relocated the edit block link to the top of the list on the block layout page.

  • πŸ‡ΊπŸ‡ΈUnited States xjm

    Thanks for your help updating this patch. In the future, when using a patch workflow, provide interdiffs β†’ for your patches. That allows reviewers to evaluate your changes.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Environment: PHP 8.1 & MariaDB 10.3.22
    last update 9 months ago
    Patch Failed to Apply
  • Merge request !5941provide helpful links β†’ (Open) created by smustgrave
  • Pipeline finished with Failed
    6 months ago
    #67604
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Pushed up some of the feedback from #290.

    290.3 will probably need all the tests redone especially if we do 290.4

    As far as using the hooks, have to do some trickery to get the name of the menu. Not sure can figure out the view name/display.

    So we sure this is the approach to take?

  • Pipeline finished with Failed
    6 months ago
    Total: 162s
    #67784
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    As far as using the hooks, have to do some trickery to get the name of the menu. Not sure can figure out the view name/display.

    We should have the block entity in scope.

    From there we can get the base block plugin ID.

    $plugin = $block->getPlugin();
    $plugin_id = $plugin->getBaseId();
    if ($plugin_id === 'system_menu_block') {
      $menu_id = $block->getDerivativeId();
      $menu = \Drupal\system\Entity\Menu::load($menu_id);
      $menu_name = $menu->label();
    }
    

    If the plugin ID is system_menu_block

  • Pipeline finished with Canceled
    6 months ago
    Total: 181s
    #71193
  • Pipeline finished with Failed
    6 months ago
    Total: 624s
    #71195
  • Pipeline finished with Success
    6 months ago
    Total: 585s
    #71201
  • Status changed to Needs review 6 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Addressed feedback from #290

  • Status changed to Needs work 6 months ago
  • πŸ‡§πŸ‡ͺBelgium Wim Leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Another round of feedback 😊 Looking great in general, just relatively nitpicky things (one pattern of which is an actual bug though). Left suggestions on how to harden the test coverage.

  • Pipeline finished with Success
    6 months ago
    Total: 512s
    #71617
  • Status changed to Needs review 6 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Addressed feedback.

  • Pipeline finished with Success
    5 months ago
    Total: 599s
    #76314
  • Status changed to Needs work 4 months ago
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Left some comments.
    This is looking really tidy now, much smaller diff, nice and clean

  • Status changed to Needs review 4 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Addressed feedback.

  • Pipeline finished with Success
    4 months ago
    Total: 605s
    #101878
  • Status changed to Needs work 3 months ago
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Left another review

  • Pipeline finished with Failed
    2 months ago
    Total: 994s
    #153581
  • Status changed to Needs review 2 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Addressed feedback.

  • Pipeline finished with Success
    2 months ago
    #153602
  • Pipeline finished with Success
    2 months ago
    Total: 1041s
    #155536
  • πŸ‡·πŸ‡ΈSerbia ivanilic

    Hi
    if I understood correctly, this would give me option to edit custom blocks in layout builder (option in contextual/operational links in layout builder for editing blocks imported from custom block library/block_content module).
    Is there any patch for 10.2 planned?
    I tested patch from #207 but there is no option for editing custom blocks in layout builder.

    Thanks!

  • πŸ‡·πŸ‡ΈSerbia ivanilic

    Hi
    if I understood correctly, this would give me option to edit custom blocks in layout builder (option in contextual/operational links in layout builder for editing blocks imported from custom block library/block_content module).
    Is there any patch for 10.2 planned?
    I tested patch from #207 but there is no option for editing custom blocks in layout builder.

    Thanks!

  • Pipeline finished with Failed
    about 2 months ago
    Total: 176s
    #160179
  • Pipeline finished with Canceled
    about 2 months ago
    #160200
  • Pipeline finished with Failed
    about 2 months ago
    #160201
  • Pipeline finished with Success
    about 2 months ago
    #160208
  • Status changed to RTBC about 2 months ago
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    This is looking good, no new APIs and some nice UX wins

    Thanks for keeping at it @smustgrave!

  • Pipeline finished with Success
    about 2 months ago
    Total: 570s
    #160233
  • Pipeline finished with Success
    about 2 months ago
    Total: 526s
    #165093
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Saving issue credit

  • Status changed to Fixed about 2 months ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Committed 0fc730b and pushed to 11.0.x. Thanks!
    Committed f8a34d3 and pushed to 11.x. Thanks!
    Committed 98887e8 and pushed to 10.4.x. Thanks!
    Committed 1b83f79 and pushed to 10.3.x. Thanks!

    • alexpott β†’ committed 1b83f796 on 10.3.x
      Issue #1956134 by smustgrave, dawehner, larowlan, jibran, jbloomfield,...
    • alexpott β†’ committed 98887e87 on 10.4.x
      Issue #1956134 by smustgrave, dawehner, larowlan, jibran, jbloomfield,...
    • alexpott β†’ committed 0fc730be on 11.0.x
      Issue #1956134 by smustgrave, dawehner, larowlan, jibran, jbloomfield,...
    • alexpott β†’ committed f8a34d34 on 11.x
      Issue #1956134 by smustgrave, dawehner, larowlan, jibran, jbloomfield,...
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • πŸ‡―πŸ‡΄Jordan abu-zakham

    Re-roll patch #290 for 10.2.x

Production build 0.69.0 2024