Fix Bookmarks view is missing a display

Created on 13 June 2023, over 1 year ago
Updated 5 August 2024, 5 months ago

Problem/Motivation

Because no display is defined by this module's config, in order to add a display to the Bookmarks view, you first need to define the first display. Doing so will break the tabs at the user profile's contextual links.

Steps to reproduce

  1. Attempt to add a display to the provided Bookmarks view.
  2. Choose the Page display plugin.
  3. Specify the path /users/%user/bookmarks to match the exiting route.

Note: It is important to name the argument %user when using contextual filters with Views Entity Form Field as is done in this view, otherwise an exception will be thrown.

Rather than adding a display, Drupal has required you to specify a display plugin (Page, Attachment, etc) for this first display now being defined. You've gone with Page, since that's most appropriate. But, notice that you haven't specified a Menu Tab.

Visit the page, and note how the contextual links disappear.

Let's fix that. Go back and edit the view, open the Menu configuration and choose Menu Tab and enable Context. Save your changes and view the page.

Now you'll see that the contextual links have returned, but that the Bookmarks tab is duplicated.

Proposed resolution

  1. Remove the route and links configuration defined in this module.
  2. Recreate the view and export.
  3. Ensure that the Page display plugin is used and that the path is supplied and the contextual Menu Tag is configured, replacing the route and links task configuration files.
๐Ÿ› Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States jcandan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @jcandan
  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States jcandan

    This patch removes the controller, route, and link task (contextual link, user profile tab). These are all replaced by the updated View configuration.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States jcandan

    Accidentally included a project specific change in #2. Re-rolled.

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States jcandan

    Patch #3 doesn't apply the same permission rules. Need to specify a views permission handler that allows view access for owners and those with "access others bookmarks" permissions.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States jcandan

    Also needs to add the title on the default display.

     display:
       default:
         ...
         display_options:
    +      title: Bookmarks
    
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia arpitk

    Updated patch to include default view default display title.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States jcandan

    After some digging, to replace the access checks removed, this patch's view is going to need the following permissions checks:

    • access others bookmarks
    • Current user is viewing own bookmarks list
  • Status changed to Needs review 5 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States jcandan

    I was able to solve the views access constraint noted in #7.

    It still needs a hook update for the views changes. For now, I pushed this patch and MR up to get community feedback.

    Anyone applying this patch wanting to adopt the views config changes may run the following:

    cat web/modules/contrib/bookmarks/config/optional/views.view.bookmarks.yml | lando drush config:set --input-format=yaml views.view.bookmarks ? -
    
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States jcandan

    I guess I need to update the target branch. Considering there will be a hook_update_N(), this should bump minor version from 1.0.x to 1.1.x, right?

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States jcandan

    I'd also like to rename the Views Access plugin.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States jcandan

    Fixes a bug with Bookmarks tab not showing.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States jcandan

    We've adopted patch #12 to a production project, I am happy to place this to RTBC; however, I am chewing on whether this needs a hook update for the veiws.view.bookmarks changes and whether this would need a major, minor, or patch version bump.

    Obviously, the fix is adopted for any new install. But, for this fix to apply to existing installations would override their existing Bookmarks view--this could be considered a breaking change requiring a major version bump.

    The way we applied the change was to simply import the single updated configuration from this module, and then used git to help us track which changes we wanted to keep:

    cat web/modules/contrib/bookmarks/config/optional/views.view.bookmarks.yml | drush config:set --input-format=yaml views.view.bookmarks ? -
    

    I imagine we could just bump the patch version and include this instruction in the release notes.

    So, the above boils down to, either we:

    1. Include a hook update and bump the major version.
    2. Include the single config import instructions in the release notes and bump the patch version.

    Opinions welcome.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States jcandan

    Leaving this one last note here for if we do decide to go with a hook update.

    function bookmarks_update_VERSION() {
      $config_factory = \Drupal::configFactory();
      $view = $config_factory->getEditable('views.view.bookmarks');
    
      if ($view->get('display.default.display_options.access.type') != 'bookmarks_view_access') {
        $view->set('display.default.display_options.access.type', 'bookmarks_view_access');
        $view->set('display.default.display_options.title', 'Bookmarks');
        ...
        $view->save();
      }
    }
    
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States jcandan

    This also solves a previously hidden views permissions issue which prevented non-admin users from seeing the links and title fields reported at ๐Ÿ› Fix bookmark link not shown for non-admin users Fixed #8 ๐Ÿ› Fix bookmark link not shown for non-admin users Fixed .

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States jcandan

    Still awaiting community feedback on options 1 or 2 noted in #13. ๐Ÿ› Fix Bookmarks view is missing a display Needs review

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States jcandan

    If it really is a breaking change, that warrants a major bump. But, Iโ€™m beginning to think it is not a breaking change. The controller and route were in place because the view had not controlled that without a page display. With this change, it does. It also shifts access control to the view with a new view access plugin. So, all the update is confined to the one view.

    With a hook update, we could override any customizations they may have made to the view. Without the hook update, if they donโ€™t run the view update config:set, they wonโ€™t get the changes and itโ€™ll break.

    Iโ€™m of the opinion that if they customize a module-provided view, any config changes upon update is thereโ€™s to deal with.

    That said, Iโ€™m for a minor update to 1.1.0 and a hook update to close out this ticket.

Production build 0.71.5 2024