New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WidgetsList->remove uses translated $widgetName => cannot actually remove widgets #19389
Comments
Thanks for reporting this @Prinzhorn, the detail is much appreciated. It looks like there is an inconsistency in naming with some widgets setting their name to the translated text and some using the translation key. For API use there should be a consistent language independent name, like the translation key. Translation keys for widgets could be found by looking in I'll mark this issue for prioritization by our product team. |
What I've seen in some frameworks and what might work well is outputting HTML comments when in development mode. So that you get something like this: <!--<General_Pages>-->
...The actual widget HTML...
<!--</General_Pages>--> So that when inspecting the HTML I can see what each widget is called (e.g. I don't know anything about the Matomo architecture but this might be trivial to add in some central place that renders widgets (server and client side). Could you clarify one thing for me: in order to remove a submenu (an entire I can easily remove the entire "Visitors" menu by using |
@Prinzhorn Do I understand that correctly, that you actually want to remove the menu entry? Or do you also want to make the widgets unavailable on the dashboard? |
@sgiehl we are setting up Matomo for some clients using only log importing. So I was asked to remove some menus because they might confuse the users and cause questions (e.g. anything "Real-time"). We have configured dashboards with only relevant widgets but yes, it totally makes sense when useless (with log importing) widgets would be entirely removed. So if the current API was fixed I guess that solves all my problems, but being able to remove entire subcategories would also make things easier. |
@Prinzhorn The "problem" with the widgetlist here is, that it is generated from two sources. Once source is the manually defined widgets, that are defined using a WidgetConfig. For those the name is untranslated. The other source are the Report classes, which might configure custom widgets or use the default factory. The default factory uses the reports name, which is currently translated. |
Note: I think it might make more sense to introduce a new method |
Copying this from the docs caused > Unmatched '}' and fixing it caused > Call to undefined method Piwik\Plugins\API\Reports\Get::getCategory() and logging `getCategoryId()` shows that `Actions` is not correct either. But using `General_Actions` doesn't remove any menus either, even though `unset` is called. I feel like the first person using these APIs (refs matomo-org#19389)
@sgiehl I tried that, see #19414 even with the fixed docs I can't seem to get it working. Is anyone using these APIs? grep.app doesn't show any results other than this repo (https://grep.app/search?q=Report.filterReports).
Makes sense, otherwise this would also be a breaking change for people who rely on the current behavior and use English interface exclusively. |
Copying this from the docs caused > Unmatched '}' and fixing it caused > Call to undefined method Piwik\Plugins\API\Reports\Get::getCategory() and logging `getCategoryId()` shows that `Actions` is not correct either. But using `General_Actions` doesn't remove any menus either, even though `unset` is called. I feel like the first person using these APIs (refs #19389)
Originally this was confirmed as a bug in I just want to make sure that: Both are fixed and From what I can tell there is currently no reliable way for me to remove individual submenus in this menu on the left Is this correct or is there a way? |
I'm trying to use
Widget.filterWidgets
to remove certain widgets we don't need. This works for removing a whole category, e.g.$list->remove('Marketplace_Marketplace');
removes the entire menu with all submenus. However, you cannot reliably use the second argument. I was trying to remove a particular menu, e.g. "Behaviour" -> "Site Search". So I tried several things such as$list->remove('General_Actions', 'Actions_SubmenuSitesearch');
but I didn't seem to get anywhere. So I tried to track this down and added:right here between the two ifs:
matomo/core/Widget/WidgetsList.php
Lines 142 to 143 in 260f512
And to my surprise this is what I get for
$list->remove('General_Actions', 'Actions_SubmenuSitesearch');
. A mix of keys likeActions_WidgetEntryPageTitles
and actual translations likePages Following a Site Search
.If I switch my user to German I get
So clearly there is something wrong. Comparing the passed
$widgetName
with a translation and not with a consistent key has no place in an API. I also still haven't been able to actually remove anything but an entire menu tree. Surely I must be doing something wrong?Expected Behavior
I can use
WidgetsList->remove
to remove a specific widget.Current Behavior
I can't and for most widgets it would break once the user uses a different language.
I personally thought I can just use the
subcategory
URL parameter to figure out what the second argument needs to be if I want to remove a particular menu item. But that doesn't seem to be it, becausesubcategory
are what actually contain the widgets? So I think we actually have two different issues here:But how do I get
VisitTime_ByServerTimeWidgetName
? If I look at the UI how would I ever get the correct translation key? In fact it only ever appears in the documentation (https://github.com/matomo-org/matomo/search?q=VisitTime_ByServerTimeWidgetName) and doesn't seem to actually be an existing key? So I can't even use it to find relevant code to find a way to figure out other keys.Possible Solution
Use the translation key and not the translation? And also add info to the documentation how to find the key.
Steps to Reproduce (for Bugs)
I hope my explanation above is enough to understand the problem
Your Environment
Docker Matomo
4.10.1
The text was updated successfully, but these errors were encountered: