Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
For performance reasons,
in Menu/ViewsMenuLink::getTitle()
Proposed resolution
Get the translated value from the config without instantiating the view.
And/or for a non-multilingual site, get the title and description just from the plugin definition the way MenuLinkContent does to avoid loading the entity.
Remaining tasks
- investigate if it is possible
User interface changes
No.
API changes
No?
Comment | File | Size | Author |
---|---|---|---|
#9 | 2310379-9.patch | 3.04 KB | pwolanin |
Comments
Comment #1
pwolanin CreditAttribution: pwolanin commentedComment #2
dawehnerThe easiest way would be probably to check whether config translation is enabled, or rather whether there is any dynamically altering of config in the wild.
Comment #3
johanv CreditAttribution: johanv commentedI will try to fix this.
Comment #4
johanv CreditAttribution: johanv commentedWhen I read this first, I thought this would be easy. It isn't :-) Probably because I am new to Drupal 8, so I still have to find my way in configuration, views menu links and translation.
Because I won't be able to fix this today, I will write down what I found out, maybe it is helpful for someone else.
Menu/ViewsMenuLink::getTitle() (which is in core/modules/views/src/Plugin/Menu/ViewsMenuLink.php) is called to render menu items generated by views. You can create one by creating a new view, display it on a page, and create a menu item for this page. ViewsMenuLink:getTitle will return the localized title of the view you created.
ViewsMenuLink implements MenuLinkInterface. So we will have to reimplement getTitle, so that it can return the localized title without having to instantiate the complete view. Sounds fair enough.
Now the issue suggest to get the translation from 'the config'. I am not sure yet which config is meant.
The other suggestion refers to MenuLinkContent. For 'MenuLinkContent', getTitle is implemented as follows:
I am not sure how this translates to MenuLinkInterface.
Sorry I couldn't work this out. Maybe I'll look at it again some day, when I am getting more used to the Drupal 8 architecture.
Comment #5
jibranComment #7
dawehnerOne related issue: #2716019: View titles in breadcrumb and metatag title don't get properly translated
Comment #8
pwolanin CreditAttribution: pwolanin as a volunteer and at SciShield commentedSo, I think we just have to read the property out of the view (config entity)?
I assume that's translated, if needed when the config entity is loaded?
for the content view:
Comment #9
pwolanin CreditAttribution: pwolanin as a volunteer and at SciShield commentedRoughly like this (need to test that config overrides and translations work right)