- Issue created by @mandclu
- π³πΏNew Zealand quietone
Is this a duplicate of π Views does not create parent local task for a default local task Needs work ?
- Status changed to Closed: duplicate
5 months ago 9:36am 10 August 2024 - π¨π¦Canada mandclu
It definitely looks like it. I tried to find an existing issue, but apparently my Google-fu was not up to the task. Thanks for pointing me in the right direction.
- Status changed to Active
5 months ago 9:58pm 10 August 2024 - π¨π¦Canada mandclu
Actually, having gone through the comments and the patches on that issue, I realize that while similar, it is specifically about a default tab where the parent is meant to be a tab. Theoretically the fix needed here could be in a single MR, but since the needed fix would have to be implemented in different places anyway, I think it makes to specifically address the creation of a parent menu link separately.
- Merge request !9174Implement creation of normal menu link as parent of a default tab β (Open) created by mandclu
- Status changed to Needs work
5 months ago 6:38am 12 August 2024 - π¨π¦Canada mandclu
Here's a first pass. There are one or two places that could use a little factoring, and it also needs tests.
- πΊπΈUnited States wattdesigns
So, here's my problem. I'm having the exact same issue as above except I don't know how to fix it. I have a page view and have tried numerous configurations on the menu tabs/default menu tabs and I can make the page show up if I manually type in the menu link. However, the tabs do NOT appear on the main parent page, but they DO show up on the direct loading of the view page. So, basically, my menu tabs show up on the view that I am viewing, but not on the page before that (the one I want a link to take me to the view).
Summary, my menu tabs show up on the page that if clicked, they would go to, but not the page before that so you don't have to manually put in the view link.
Hopefully that makes sense as my brain is all fuzzy trying numerous configurations for days now. Please help!!!!
The temporary fix is to create a menu link in a mymodule.links.menu.yml file
mymodule.link_id: title: LINK TITLE route_name: view.VIEW_NAME.DISPLAY_NAME menu_name: MENU_NAME weight: 99
- πΊπΈUnited States wattdesigns
Thank you so much for the SUPER Quick reply. Could you please build it out a bit? So, I can create a file named that, with the code you posted (altered to fit my titles), but what do I do with it then? Thank you so much!
you need to make a custom module , and put this file in the module's directory.
A module is just a directory with an info file.
See any module for an example, and note that many modules will have a links.menu.yml for you to look at.
the link_id is arbitrary, but must be unique to the links in your module.
weight is relative to the other links in the same menu.
Then you can put your views tab under this link as the default tab.- πΊπΈUnited States wattdesigns
I got a WSOD when I uploaded my module. Looks like my error is The 'core_version_requirement' key must be present???
- πΊπΈUnited States wattdesigns
This was so much easier in Drupal 7. Sigh. I'm sure there's a super cool reason they changed this, but it's sure frustrating.
- πΊπΈUnited States wattdesigns
OK, so more details. I have a view with contexual filters that makes a signin sheet for a registration content type. Everything about the view works like a champ. The content type is referenced using /training/%/main and the view that I have has a path of /training/%/main/signin with the % being the node ID for the filter. Originally, I made a page display (that works) and use the path /training/%/main/signin and then made a default menu tab for it. Next, I copied that display and kept the same path, but made a menu tab for it. So if I go to /training/169/main I see no tabs, and if I go to /training/169/main/signin I get to see my view filtered by node 169 PLUS it has two menu tabs at the top. That's my best case so far.
So, next I made a module called viewstabsignin to allow for other modules for other tabs. I created a directory and called it it viewtabsignin. Next I created a file called viewstabsignin.info.yml and put it in the directory. That file is pasted below:
name: Views Tab Signin
type: module
description: My custom module for Drupal 10 to add a views tab parent menu
package: Custom
version: 1.x
core: 10.x
dependencies:
- drupal:viewsNext I made a file called viewstabsignin.links.menu.yml in that directory. It includes this:
viewstabsignin.link_id:
title: Sign-in
route_name: view.registration_lists.sign-in
menu_name: signin
weight: 99I updated the title, the route_name to match my view, the menu_name to be what I wanted it to say, and left the Weight for now.
When I upload that to my modules directory, I get white screens when trying to view modules.
That's where I'm stuck. I'll look around for a better sample info file.
- πΊπΈUnited States wattdesigns
OK! EUREKA! I got the module to be able to be enabled! I updated the info file to be the following:
name: Views Tab Signin
type: module
description: Views Tab for Signin
package: Contrib
core_version_requirement: ^9 || ^10# Information added by Drupal.org packaging script on 2023-12-11
version: '1.0.0'
project: 'viewstabsignin'
datestamp: 1702287967NOW, can I get the tab to show up????
- πΊπΈUnited States wattdesigns
UGGGGGG! Now I can't flush the cache without a Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[40001]: Serialization failure: white screen of death.
White screen is a syntax error in the php (not the yml file I think)
However indentation is important in yaml files
For white screens look in the server log e.g.
/var/log/apache2/error.log
and/or enable error displays in php.
Either by editing php.ini or by putting a directive in the code like
ini_set('display_errors', 1);
Contrib isn't a package, better use 'custom' or 'My site'
signin seems an unlikely name for a menu, is that a menu you created and which is visible in admin/structure/menu when menu_ui module is enabled?- πΊπΈUnited States wattdesigns
OK, got some questions from that. Thanks so much for leading me down the right path!
Indents....so on the file you supplied, there's a small indent in each of the lines past the first one. Just checking that should be there.
Contrib as package..... updated to custom which seems better. Glad you noticed that.
The menu item. I think this is where I'm messing up. So, I don't have a normal menu item because I wasn't sure how to do that with a view that changes for every content type. So would I make a parent menu item (I know how to make menu items, so that's easy) called say Tabsmenu would I then add a menu under that parent named Signin? What would the path for that menu item be as it's something tagged onto every content type of training? Is it OK to put the % like in the contextual filter?
This is probably what I'm messing up.
Thanks for explaining! I'm not a coder at all, but I've been Lego'ing Drupal for a long time.
Sorry because I work so much in code I forgot to mention that you don't need a custom module to make a menu item yes you can just use menu_ui at admin/structure/menus.
Tabsmenu would be the name of a menu. When you say menu item I think of 'Menu link'
You don't make a menu for tabs (tasks)
Tabs have a root which is the ID of a menu link, but views is managing tabs for you.
So make a menu item either as I said before with your custom module and indented yml file OR via admin/structure/menu
Then in your views display -> menu section create a default menu tab and other tabs with that that menu item as the parent.
Sorry haven't got time to get my head into content types, but you may need to create a display for each content type or script the creation of these tabs and menu links.- πΊπΈUnited States wattdesigns
OK, so I made a menu called Tabsmenu that included no links in it. I used the default menu tab (with a parent link of Already Exists). Then I made another page display that's identical, but changed to a normal menu tab with a parent of the Tabsmenu.
That still didn't work. No menu tab. So I'm still missing something. 8-( I'm sure it's staring me right in the face.
HOWEVER, you may have given me an idea. I actually don't NEED it to be a tab. If I can use a token in the normal menu link, I can display the menu in a block on that content type, with the contextual filter, and be just fine. Looks like there's an alpha release of menu_token module which appears to allow tokens in the menu link address. If that works out, I should be able to do what I need. I'll try it tonight when I have access to my Composer terminal.
- π¨π¦Canada mandclu
@wattdesigns have you tried applying the patch? The goal of this issue is really to figure out how we can get the core Views functionality to work the way the Views UX promises it will, e.g. creating a menu item when asked. I agree with your experience, I have not been able to simply set the menu item to "already exists" and have it work as intended with the tabs.
- πΊπΈUnited States wattdesigns
Mandclu,
Sorry for going off scope there a bit. You're right.
However, I didn't see a patch that passed? I just followed the merge request you had and see a patch in that one. I can give that a try. If it works, that would be awesome!
- πͺπΈSpain plopesc Valladolid
Than kyou for the patch @mandclu
We're experiencing this same issue and using the custom menu link in the yml file approach as a workaound.
Tested your patch locally (Using core 10.3.10) and here is my feedback:
- Patch applies cleanly even for 10.3.x. yay!
- When clearing cache I get a few instances of this warning:
Undefined array key 1 PathPluginBase.php:398
. I guess it's related to views using the Default Menu Tab option where the new fields have not been setup manually - Edited the one of the views and filled the new "Parent" field when Normal menu link option is selected
- The menu link is created as expected, nested below the parent designated
2 issues noticed with the new menu link created:
- The menu link title is taking the tab's title instead of the menu link title
- The menu link weight is taking the tab's weight instead of the menu link title
This MR is a great progress. Just some minor adjustments are needed.
- π¬π§United Kingdom oily Greater London
An MR is needed with the patch applied forked from 11.x (main) branch. The code can thus be back-ported eg to 10.3.x.
Test coverage is needed.
- πͺπΈSpain plopesc Valladolid
Yes, this issue should follow the standard path.
I was just pointing out the issues I found when testing the code locally. Even if tests are still needed, some minor adjustments are required, apparently.
- π¬π§United Kingdom oily Greater London
@plopesc Would be great if you could add comments to the MR suggesting code changes to fix the 2x things you identified. It would help someone (like me) to fix the code.
- πͺπΈSpain plopesc Valladolid
@mandclu Went ahead and made a couple of small changes to adapt the MR to make it work with dynamic menu titles and descriptions in ViewsMenuLink.
- πΊπΈUnited States smustgrave
Believe the kernel test failure is relevant here.