For the sake of a simple example, lets say we have a view 'people/owners/%' with default title "Profile" and a Contextual Filter on field "last_name". The Contextual Filter has configuration "Override Title" checked with override value of "{{ title }}". The view is configured so that going to "/people/owners" returns 404, for no results. So, the default "Profile" title should always be overriden, as the view only works when a valid last_name is provided. When we go to /people/owners/johnson, the title is accurately overridden to say "Jeffrey Johnson" on the page. However, the breadcrumb shows "People / Owners / Profile" instead of "People / Owners / Jeffrey Johnson". I've tried changing the Default title from "Profile" to "{{ title }}", but this doesn't work, as I don't believe that field accepts twig input.

I've checked configurations on the Breadcrumb block, as well as the breadcrumb settings in bootstrap sub-theme's COMPONENT >> BREADCRUMBS sections, and don't see anything pertaining to title overrides.

I've searched for similar issues, but haven't found any. If this is a duplicate, I apologize, I must have missed something and would greatly appreciate someone pointing me in the right direction. Or, if this sounds like it's not a core issue, but rather a theme issue, just let me know and we can close this and I'll open a new issue on Bootstrap theme.

CommentFileSizeAuthor
#74 interdiff_65-74.txt1.54 KBklidifia
#74 2787051-74.patch4.13 KBklidifia
#73 interdiff_65-73.txt1.54 KBklidifia
#73 2787051-73.patch1.54 KBklidifia
#72 interdiff_65-72.txt1.54 KBklidifia
#72 2787051-72.patch4.13 KBklidifia
#71 2787051-nr-bot.txt1.81 KBneeds-review-queue-bot
#65 2787051-65.patch4.81 KBguptahemant
#62 interdiff_59-62.txt624 bytessrilakshmier
#62 2787051-62.patch3.88 KBsrilakshmier
#59 2787051-9.2-59.patch4.69 KBFabsgugu
#57 interdiff_45_57.txt598 bytesanmolgoyal74
#57 2787051-9.1-57.patch4.55 KBanmolgoyal74
#45 2787051-9.1-45.patch4.54 KBaleevas
#40 drupal-view_title_with_contextual_filters-2787051-40.patch4.43 KBextralooping
#40 drupal-view_title_with_contextual_filters-8.8-2787051-40.patch4.44 KBextralooping
#40 interdiff_39-40.txt832 bytesextralooping
#39 interdiff.2787051.38-39.txt2.37 KBaleevas
#39 2787051-39.patch4.21 KBaleevas
#38 drupal-view_title_with_contextual_filters-2787051-38.patch4.2 KBcodebymikey
#28 drupal-view_title_with_contextual_filters-2787051-28.patch2.07 KBphjou
#26 drupal-view_title_with_contextual_filters-2787051-26.patch1.99 KBphjou
#25 drupal-view_title_with_contextual_filters-2787051-25.patch1.88 KBphjou
#16 2787051-16.patch1.78 KBrobertom
#15 2787051-15.patch1.54 KBrobertom
#44 drupal-view_title_with_contextual_filters-8.9-2787051-44.patch4.54 KBarpad.rozsa
#44 drupal-view_title_with_contextual_filters-8.8-2787051-44.patch4.55 KBarpad.rozsa
#44 interdiff_40-44.txt1.46 KBarpad.rozsa
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

xeM8VfDh created an issue. See original summary.

SylvainM’s picture

I have the same bug, with 8.1.7

xeM8VfDh’s picture

Thanks for the feedback @SylvainM. Still not sure if this is a core issue or theme issue. Hopefully a dev will chime in shortly.

dawehner’s picture

Well, to be honest the default implementation is sort of designed to not provide that level of flexibility in exchange for better performance.

There are contrib modules which have more flexibility, like https://www.drupal.org/project/crumbs, but its not available in 8.x yet :(

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

ac’s picture

This is still present as an issue.

From a user's point of view, one would assume if the view's title is correctly shown in the breadcrumb then when it is overridden in a contextual filter, the overridden title would also be shown in the breadcrumb.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Greg Boggs’s picture

Given how long this issue has been open, unless someone's feeling motivated to fix this in core, I can fix this in easy breadcrumb:

https://www.drupal.org/project/easy_breadcrumb/issues/2927421

xeM8VfDh’s picture

@Greg Boggs, go for it!

I personally think it should be fixed in core, but I am not even sure what the core developers/maintainers think of this, as none of them have explicitly chimed in on this.

Greg Boggs’s picture

Cool. I haven't dug into this one yet, but working around a bug in page manager was only a few lines of code in Easy Breadcrumb. So, I am expecting something similar on this one. I'll update here when we have a decent patch for Easy Breadcrumbs incase folks wanna steal it :)

~G

xeM8VfDh’s picture

awesome, thanks a lot Greg!

andyhawks’s picture

Any updates on this for core Greg?

robertom’s picture

Version: 8.5.x-dev » 8.7.x-dev
Component: other » views.module
Status: Active » Needs review
FileSize
1.54 KB

Attached a proposed patch

robertom’s picture

FileSize
1.78 KB

new version of the patch with the missing dockblock

a.sinitsa’s picture

#16 work nice for me

dhumed’s picture

I have applied the patch in #16 but that still does not fix the issue for me. I have a view that shows content instead of fields but it is using a contextual filter with the override title option. The title of the page is properly overriden but that is not reflected in the breadcrumb nor the title attribute of the browser window.

keopx’s picture

Status: Needs review » Reviewed & tested by the community

Works for me.

* Drupal 8.5.6 (last stable release).
* menu_breadcrumb 1.6

Languages:

* Basque (default)
* Spanish

dobe’s picture

I tried #16 against Drupal 8.5.6 and I am experiencing the same issue as #18. Title shows overridden, breadcrumb does not.

xeM8VfDh’s picture

Status: Reviewed & tested by the community » Needs work

I'm going to tentatively change the status back to "Needs work" due to #18 and #20...

MrTucker’s picture

If anyone is looking for a workaround, I was able to get the desired effect by adding twig directly to the view's title field (not overriding the title with the contextual filter itself. )

Example: My Title {{ arguments.name }}, where the arguments is the name of a taxonomy term.

The following thread pointed me in the right direction.
https://www.drupal.org/project/drupal/issues/2912332

Drupal 8.6.2

xeM8VfDh’s picture

thanks @mrshawntucker! I will try that out.

EDIT: Unfortunately, your suggestion doesn't work for me for various reasons. I should note, I am running Drupal 8.6.2 on PHP 7.2. Firstly, my use case is such that I don't want to display any of the contextual arguments in the title, I want to display values from the content object itself. It looks like your solution only allows you to use twig variables corresponding to the contextual arguments. On top of that, using those simply did not work for me. I feel like I tried that approach back when I originally reported this bug, and was somehow able to get the contextual argument twig variables to work, but it isn't working for me right now, and I don't want those variables anyways.

Oddly enough, if I remove the title overriding, and place {{ title }} in the Title field, that variable actually works. The title is displayed accordingly (based on the title of the content object). But, shittily enough, this does NOT affect the breadcrumb, which simply shows "{{ title }}". I think that's why I ended up doing the override, so that I could put something half-meaningful in the "Title" field, for the breadcrumb, and then use the "{{ title }}" title override to actually affect the title displayed on the page.

I agree with @websiteworkspace's sentiment on the page you linked... it is quite bizarre that this basic and critical feature is broken in Views. Luckily, my requirements aren't that strict, but I could see this preventing some people from being able to use D8 Views/Breadcrumbs. This functionality is very much the point of the Views module.

robertom’s picture

Sorry for my bad english.

I'm in a new project and I found that my patch #2787051-16: Views contextual filter's title override is invisible to TitleResolver doesn't work for me when I have a views path like news/%

in this case I set the {{ arguments.name }} in the contextual filter title override and, for breadcrumb, I need to set the display title as: "%arg_0" (without apply the patch)

@see: PathBasedBreadcrumbBuilder::build() and TitleResolver::getTitle()

phjou’s picture

Hi,

It doesn't work for me too. When you are using a contextual filter, you have to set the arguments in order to see the overridden title.
I just tried a new patch which is working for the current view.

I get the parameters from the current route, but this is probably not the good way to do it. Indeed, if you have several views like this in your breadcrumb, it will probably break the other view names that are not your current view.

The parameters maybe should be passed to the title function in order generate the correct title. I put the patch that is working with the current view but I will try to find some time to dig into this and check that the bug I suspect is really here.

@mrshawntucker For me the twig is working only in the Title block of the page but not in the breadcrumb or in the title tag that defines the name of the browser tab.

phjou’s picture

I have just noticed that the route_match was already there, I should sleep it's really late around here ^^

So, there is a better patch that should apply the override title in the breadcrumb and in the head html tag.
Tell me if it works for you :)

Concerning using the argument name in the override title, there are plenty of issues concerning this and it's a different problem:
#2915934 #2640994

phjou’s picture

Status: Needs work » Needs review
phjou’s picture

Ok I have just found out that this code contains also "view_id" and "display_id".

$parameters = $route_match->getParameters();

But when we set the arguments, we only should have arg_0, arg_1 etc... So I had to remove those two in order to correct a bug when I had multiple contextual filters in the same view URL. But I don't even know how it was working for one before....

Anyway, I have removed these two parameters manually because I haven't found a function in the core that do something like that, but I am sure there is some code I have not found that could help.

In this Feed.php class from the core (line 287), they build the title with the same way we did.

    $clone->setArguments($this->view->args);
    $clone->setDisplay($this->display['id']);
    $clone->buildTitle();
juampynr’s picture

This blog post's solution works: https://medium.com/@philw_/enable-views-contextual-filter-page-title-overriding-in-drupal-8-493b61512343

phjou’s picture

@juampynr Thanks for the tip :) But it should work without this fix. And I am not sure that it's working in the breadcrumb when the view is a parent of the current page.

Lendude’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Makes sense that the replacements need this context, nice work on this.

+++ b/core/modules/views/src/Plugin/views/display/PathPluginBase.php
@@ -130,6 +130,7 @@ protected function getRoute($view_id, $display_id) {
       '_title' => $this->view->getTitle(),
+      '_title_callback' => 'Drupal\views\Routing\ViewPageController::title',

_title is redundant like this I think.

In \Drupal\views\Plugin\views\display\PathPluginBase::getRoute there is a fair amount of logic to figure out if the view uses arguments. Can we not use that to switch between _title and _title_callback, so we only do the callback if there is a chance this is needed? So maybe we can avoid the additional overhead of the callback when we can?

Also, this needs tests.

dobe’s picture

#28 just makes my pages spin. I was running into this issue as well when I tried taking a stab at figuring this issue out. Seems like the site gets Router gets in recursive loop or something. My logs have thousands upon thousands of these dependent on how long I let it go for.

Notice: Trying to get property of non-object in Drupal\views\ManyToOneHelper->addTable() (line 88 of /var/www/html/drupal/web/core/modules/views/src/ManyToOneHelper.php) #0 /var/www/html/drupal/web/core/includes/bootstrap.inc(584): _drupal_error_handler_real(8, 'Trying to get p...', '/var/www/html/d...', 88, Array)
#1 /var/www/html/drupal/web/core/modules/views/src/ManyToOneHelper.php(88): _drupal_error_handler(8, 'Trying to get p...', '/var/www/html/d...', 88, Array)
#2 /var/www/html/drupal/web/core/modules/views/src/ManyToOneHelper.php(187): Drupal\views\ManyToOneHelper->addTable(Object(stdClass))
#3 /var/www/html/drupal/web/core/modules/views/src/Plugin/views/argument/StringArgument.php(224): Drupal\views\ManyToOneHelper->ensureMyTable()
#4 /var/www/html/drupal/web/core/modules/views/src/ViewExecutable.php(1111): Drupal\views\Plugin\views\argument\StringArgument->query(false)
#5 /var/www/html/drupal/web/core/modules/views/src/ViewExecutable.php(1873): Drupal\views\ViewExecutable->_buildArguments()
#6 /var/www/html/drupal/web/core/modules/views/src/Routing/ViewPageController.php(86): Drupal\views\ViewExecutable->buildTitle()
#7 [internal function]: Drupal\views\Routing\ViewPageController->title('track_systems_t...', 'page_vehicle_ma...', Object(Drupal\Core\Routing\RouteMatch))
#8 /var/www/html/drupal/web/core/lib/Drupal/Core/Controller/TitleResolver.php(58): call_user_func_array(Array, Array)
#9 /var/www/html/drupal/web/core/modules/system/src/PathBasedBreadcrumbBuilder.php(177): Drupal\Core\Controller\TitleResolver->getTitle(Object(Symfony\Component\HttpFoundation\Request), Object(Symfony\Component\Routing\Route))
#10 /var/www/html/drupal/web/core/lib/Drupal/Core/Breadcrumb/BreadcrumbManager.php(83): Drupal\system\PathBasedBreadcrumbBuilder->build(Object(Drupal\Core\Routing\RouteMatch))
#11 /var/www/html/drupal/web/core/modules/system/src/Plugin/Block/SystemBreadcrumbBlock.php(72): Drupal\Core\Breadcrumb\BreadcrumbManager->build(Object(Drupal\Core\Routing\CurrentRouteMatch))
#12 /var/www/html/drupal/web/core/modules/block/src/BlockViewBuilder.php(203): Drupal\system\Plugin\Block\SystemBreadcrumbBlock->build()
#13 [internal function]: Drupal\block\BlockViewBuilder::preRender(Array)
#14 /var/www/html/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(378): call_user_func('Drupal\\block\\Bl...', Array)
#15 /var/www/html/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(450): Drupal\Core\Render\Renderer->doRender(Array)
#16 /var/www/html/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender(Array, false)
#17 /var/www/html/drupal/web/core/lib/Drupal/Core/Template/TwigExtension.php(490): Drupal\Core\Render\Renderer->render(Array)
#18 /var/www/html/drupal/vendor/twig/twig/lib/Twig/Environment.php(467) : eval()'d code(319): Drupal\Core\Template\TwigExtension->escapeFilter(Object(Drupal\Core\Template\TwigEnvironment), Array, 'html', NULL, true)
#19 /var/www/html/drupal/vendor/twig/twig/lib/Twig/Template.php(215): __TwigTemplate_17ef12ba4632907f82cb69beada9aa4240f6340c59c25a2858778e287d3fcde4->block_content(Array, Array)
#20 /var/www/html/drupal/vendor/twig/twig/lib/Twig/Environment.php(467) : eval()'d code(96): Twig_Template->displayBlock('content', Array, Array)
#21 /var/www/html/drupal/vendor/twig/twig/lib/Twig/Template.php(432): __TwigTemplate_17ef12ba4632907f82cb69beada9aa4240f6340c59c25a2858778e287d3fcde4->doDisplay(Array, Array)
#22 /var/www/html/drupal/vendor/twig/twig/lib/Twig/Template.php(403): Twig_Template->displayWithErrorHandling(Array, Array)
#23 /var/www/html/drupal/vendor/twig/twig/lib/Twig/Template.php(411): Twig_Template->display(Array)
#24 /var/www/html/drupal/web/core/themes/engines/twig/twig.engine(64): Twig_Template->render(Array)
#25 /var/www/html/drupal/web/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template('themes/custom/t...', Array)
#26 /var/www/html/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(437): Drupal\Core\Theme\ThemeManager->render('page', Array)
#27 /var/www/html/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender(Array, false)
#28 /var/www/html/drupal/web/core/lib/Drupal/Core/Template/TwigExtension.php(490): Drupal\Core\Render\Renderer->render(Array)
#29 /var/www/html/drupal/vendor/twig/twig/lib/Twig/Environment.php(467) : eval()'d code(88): Drupal\Core\Template\TwigExtension->escapeFilter(Object(Drupal\Core\Template\TwigEnvironment), Array, 'html', NULL, true)
#30 /var/www/html/drupal/vendor/twig/twig/lib/Twig/Template.php(432): __TwigTemplate_0149a65ec4c3c07bf3023ca49566395837322b1f8708b4127d0d6f71bbc47e75->doDisplay(Array, Array)
#31 /var/www/html/drupal/vendor/twig/twig/lib/Twig/Template.php(403): Twig_Template->displayWithErrorHandling(Array, Array)
#32 /var/www/html/drupal/vendor/twig/twig/lib/Twig/Template.php(411): Twig_Template->display(Array)
#33 /var/www/html/drupal/web/core/themes/engines/twig/twig.engine(64): Twig_Template->render(Array)
#34 /var/www/html/drupal/web/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template('themes/custom/t...', Array)
#35 /var/www/html/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(437): Drupal\Core\Theme\ThemeManager->render('html', Array)
#36 /var/www/html/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender(Array, false)
#37 /var/www/html/drupal/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(147): Drupal\Core\Render\Renderer->render(Array)
#38 /var/www/html/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}()
#39 /var/www/html/drupal/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(148): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#40 /var/www/html/drupal/web/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php(90): Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\CurrentRouteMatch))
#41 [internal function]: Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object(Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#42 /var/www/html/drupal/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#43 /var/www/html/drupal/vendor/symfony/http-kernel/HttpKernel.php(156): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object(Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent))
#44 /var/www/html/drupal/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#45 /var/www/html/drupal/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#46 /var/www/html/drupal/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#47 /var/www/html/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(99): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#48 /var/www/html/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(78): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#49 /var/www/html/drupal/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#50 /var/www/html/drupal/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#51 /var/www/html/drupal/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#52 /var/www/html/drupal/web/core/lib/Drupal/Core/DrupalKernel.php(669): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#53 /var/www/html/drupal/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#54 {main}.

spacetaxi’s picture

#29 works for me. Thanks @juampynr

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dpeamit’s picture

Just in case anyone is looking for a workaround

 /**
  * Implements Hook_preprocess_breadcrumb.
  */
 function HOOK_preprocess_breadcrumb(&$variables)
 {
     $route = \Drupal::routeMatch()->getRouteName();
     if ($route && $variables['breadcrumb'] && 'your_view_route_name' == $route) {
         $variables['breadcrumb'][2] = array(
                    'text' => ucwords(\Drupal::routeMatch()->getParameters('node')->get('arg_0'), '-'),
                    'url' => 'add_the_url or leave blank',
                   );
     }
     $variables['#cache']['contexts'][] = 'url';
 }
dpeamit’s picture

#28 works for me, but i will stick with the pre-process till it is fully tested for all scenarios.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

codebymikey’s picture

This issue also affects views with config translation titles.

I have updated the code so that it fetches the $args using the same logic that Drupal\views\Routing\ViewPageController::handle uses, as well as caching the title statically for the issue raised in #31.

Unfortunately the use of _title isn't feasible due to potential issues with language config overrides. I think it's still worth keeping the property for API reference purposes.

aleevas’s picture

extralooping’s picture

At the moment special chars are double encoded to html entites. $view->getTitle() returns allready encoded html entites.
For the _title property of the route this did work, because it's value is passed through t() which implicitely converts it to a markup object. This does not hapen with _title_callback. As far as I can see there are two options: return a #marjup render array od pass the title through t(). I decided for the latter because it also enables translation... Attached is a new patch, an interdiff and a backport for the current 8.8 release.

codebymikey’s picture

@extralooping I would follow TitleResolver::getTitle's suggestion and return a render array instead.

I think the recommended way is to do the view translations on the config level as it's a config entity and the view title is flagged as translatable - adding the t call will trigger unnecessary translations for each language config override, and there'd be no context for the translation.

What led me to this issue was that language config title overrides were being cached in _title for all languages (e.g. if the views route cache was regenerated on language site B, site B's view title would be used on language site A,B,C,D), whereas they were meant to be language/site specific. Using the dynamic callback addresses that.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

arpad.rozsa’s picture

#40 works really good for me, with one issue other than the one in #41.
I think it would make sense in the _title_callback to cache the view title by the arguments as well. In a scenario when multiple breadcrumb items link to the same view and display, but with different arguments, both of the items get the same title.

The $view->buildTitle() is called for the same view two times in the same request and currently the second time it uses the cached $view_title, which is fine, but the two calls having different arguments, the title could be different also, therefore the arguments should be used as well when caching the title.

arpad.rozsa’s picture

Here are the patches with the changes I mentioned in my previous comment and also with changes regarding returning a render array as metniond by @codebymikey.

Since drupal 8.9 got a beta release, this patch will need to be ported to drupal 9, but I didn't have time yet to test it so now I'm just uploading patches for 8.8 and 8.9.

aleevas’s picture

mdupont’s picture

I confirm that #44 works for me on a Drupal 8.8.x site with multiple languages.

It uses the right Views config and contextual filter argument translation depending on the selected language (in my case, a translated taxonomy term name).

Also, it fixes the issue in other places in addition to the breadcrumb.

It makes TitleResolver::getTitle() to return the correct title from everywhere it is used, as you can see with something like:

$route = \Drupal::service('current_route_match')->getRouteObject();
$request = \Drupal::request();
var_dump(\Drupal::service('title_resolver')->getTitle($request, $route));

For instance, using drupal_block() from Twig Tweak in a Twig template to display the page_title_block will now return the correct overridden title instead of the default Views one.

mdupont’s picture

Title: Breadcrumb title doesn't reflect view contextual filter's title override » Views contextual filter's title override is invisible to TitleResolver

Updating the issue title to better reflect what is is about, it's not only breadcrumbs.

mdupont’s picture

mdupont’s picture

Status: Needs review » Needs work

Latest patch still needs work since it's breaking substitutions in Views.

To reproduce:

  • Create a taxonomy term view
  • Add a term ID field
  • Make it hidden
  • Add a "Global: Custom text" field
  • As text, put "{{ tid }}"
  • Watch the view crash

When the patch is applied, the tid substitution becomes a Markup object, which creates an error because _views_query_tag_alter_condition() thinks it's a query object.

Lendude’s picture

mdupont’s picture

Just tested #2716019: View titles in breadcrumb and metatag title don't get properly translated, it doesn't work with overridden Views titles AFAICS. "Static" views titles work though.

junaidpv’s picture

@mdupont, it did not crash when I followed your steps given in #49, after applying patch from #44. My Drupal is 8.8.6, maybe it happened on a D9?

mdupont’s picture

Status: Needs work » Needs review

Thanks @junaidpv, I indeed tried to reproduce on a clean install of 8.8.9-dev and did not encounter any crash.

I don't remember the setup I used last time, so maybe something else was causing the issue. Putting the status back to Needs Review, my mistake.

Note: with a multilingual site, the correct, translated views title is used in the breadcrumbs. However, when using Contextual Filters and a title override which should be an entity label, the overridden title is not translated. To determine whether it should be fixed here or in #2716019: View titles in breadcrumb and metatag title don't get properly translated.

So this time, these are the steps I took:

  • Get a fresh copy of Drupal 8.8 source from git
  • Launch it in a new DDEV environment
  • Use the URL it gives me to install Drupal (standard profile)
  • Enable the Language, Content Translation, Configuration Translation and Interface Translation modules
  • Add a second language in /admin/config/regional/language (I chose French)
  • Make taxonomy terms translatable in /admin/config/regional/content-language
  • Create a taxonomy term, with a title like "My Term EN"
  • Translate the taxonomy term to give it another label in the second language, e.g. "My term FR"
  • Create a view listing taxonomy terms, showing label and ID, with a Page display with a path (e.g. /viewpath)
  • Give a title to the view, e.g. "My View EN"
  • Filter results to only the ones with Translation Language = current language
  • Add a Contextual Filter of type Taxonomy Term ID
  • Enable title override when a value is provided for this filter
  • Put {{ arguments.tid }} as the title override
  • Save the view
  • Translate the view in the second language, translate its title to e.g. "My View FR"
  • Visit /viewpath
  • The title should be "My view EN"
  • Visit /viewpath/1 (or whatever the term ID is)
  • The title should be overridden to "My term EN". The breadcrumb may show "My view EN" as a parent, depending on your config
  • Visit /fr/viewpath
  • The title should be "My View FR"
  • Visit fr/viewpath/1 (or whatever the term ID is)
  • The title will still be "My term EN", untranslated. The breadcrumb may show "My view FR", translated correctly as a parent, depending on your config
junaidpv’s picture

It is indeed a must have fix.

We also require the ability to override breadcrumb with contextual filters, not just view title. That feature is present in D7. I created a thread for that #3156711: Bring back overriding breadcrumb with contextual filter and already submitted a patch. Please have look if anyone is interested.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Antoniya’s picture

Status: Needs review » Needs work

I applied the latest patch and was then able to override the title of my view with TX term labels. Thank you for your work so far!

However @mdupont is right – the titles are not translated and that's logical knowing that the overriding value is derived from the args/contextual filter value and not from the term entity or the URL alias of the route (e.g. both /news/term-EN and it's URL alias for DE /news/term-DE will get the same 'term-EN' title override). But maybe this is out of scope here?

I think we should update this PHPDoc since we are returning an array instead of a string:

+++ b/core/modules/views/src/Routing/ViewPageController.php
@@ -3,12 +3,15 @@
+   *
+   * @return string
+   *   The view title.
+   */
+  public function title($view_id, $display_id, RouteMatchInterface $route_match) {
anmolgoyal74’s picture

Status: Needs work » Needs review
FileSize
4.55 KB
598 bytes

Updated the docs.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Fabsgugu’s picture

Hello,
I made the patch compatible for version 9.2

Status: Needs review » Needs work

The last submitted patch, 59: 2787051-9.2-59.patch, failed testing. View results

srilakshmier’s picture

Assigned: Unassigned » srilakshmier
srilakshmier’s picture

Assigned: srilakshmier » Unassigned
Status: Needs work » Needs review
FileSize
3.88 KB
624 bytes

Tried to fix the issue in #59. Uploaded the patch.

Fabsgugu’s picture

Status: Needs review » Needs work

Patch 62 cannot work.

In the latest versions of drupal, the title function has been added to ViewPageController. However, it does not take into account the contextual filter.

A getTitle function has been added in the patch to allow the contextual filter to be taken into account. Without that, the patch will be useless.

Ideally, it would probably be better to integrate the getTitle code into the title.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

guptahemant’s picture

Status: Needs work » Needs review
FileSize
4.81 KB

Here is a patch which addresses feedback from #63 and reuses the work done in previous patches.

Please review

Status: Needs review » Needs work

The last submitted patch, 65: 2787051-65.patch, failed testing. View results

xeM8VfDh’s picture

Issue summary: View changes
Antoniya’s picture

Status: Needs work » Needs review

Tested #65 and it works great for me, thank you!

The QuickEdit test failures look random to me, maybe related to some timing issues? Triggering the bot again.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
FileSize
1.81 KB

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

klidifia’s picture

FileSize
4.13 KB
1.54 KB

The static caching and returning of the $view_title variable results in HTML entities not being decoded - altering to solve.

klidifia’s picture

Status: Needs work » Needs review
FileSize
1.54 KB
1.54 KB

Corrected

klidifia’s picture

FileSize
4.13 KB
1.54 KB
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs issue summary update

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

This could use an issue summary update with proposed solution, remaining tasks, etc.

Still needs a test case.

chike’s picture

Patch #74 is working. Thanks.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

xeM8VfDh’s picture

Status: Needs work » Reviewed & tested by the community

reviewed by @chike in #76

smustgrave’s picture

Status: Reviewed & tested by the community » Needs work

Typically reviews should provide more detail.

But this was tagged for tests and issue summary updates both which still need to happen.

Thanks

alison’s picture

I know there are other tasks before this can be RTBC, but just chiming in to say that #74 worked perfectly for us on 10.2.0, thank you so much for the fix!!

gillesv’s picture

Was also experiencing the same issue where the breadcrumb would refuse to use the views title defined by the override in the contextual filter settings, even with "Easy Breadcrumb" enabled.

The patch in #74 seems to work fine.