Problem/Motivation

As noted by markdc in #5 and #6, this module isn't functional on Views containing links where Views caching is enabled.

Steps to reproduce

See #3 and #5.

Proposed resolution

Research how Link Trail by Path may be able to be updated to support cached views.

CommentFileSizeAuthor
#4 views.view_.woordenboek.yml14.04 KBfirfin

Comments

firfin created an issue. See original summary.

caldenjacobs’s picture

Hi firfin,

Could you post an export of your View here?

It should be functional.

Thanks

firfin’s picture

Maybe I am missing something then ( if it should be functional.) There are no further settings required other than enabling the module right?
Attached is an export of my view of basic pages, just titles in a block. The block just list all titles and I need the one which is being viewed to be active. My original block grouped the titles by first letters (it is a glossary basically.)
I added a simpler block for testing purposes ( jus titles, no grouping, minimal test case.) Neither seems to work.

Thanks you for looking into this. If you need any other info I can post it.

firfin’s picture

StatusFileSize
new14.04 KB

Forgot to attach the file. replace 'view_' with 'view'.

markdc’s picture

This isn't functional for me either.

I have a view of shop categories based on taxonomy terms with the following URL pattern:
example.com/en/shop/category-1
example.com/en/shop/category-2
example.com/en/shop/category-3

No matter what page I am on in the shop, only category-1 gets the active link. It's as if it is only looking at /shop and not the following parts of the URL. Even if I am at example.com/en/shop/category-3/product-123, category-1 keeps the active-trail.

I'm using the latest Pathauto and D8.6.

Thanks if you can look at this.

markdc’s picture

Update: Setting the view's caching to none fixed it.

pol’s picture

I wonder if there is a way to fix this without changing the Views settings...

markdc’s picture

My log is full of PHP notices (issue here) in D8.6.7. Otherwise module is still working fine.

pol’s picture

Status: Active » Postponed (maintainer needs more info)

Hi,

Is this issue still valid ?

(reopen if needed)

Thanks.

sirclickalot’s picture

Hi,

All working for me on anchors - i.e. it is adding the class correctly.
Great little module, thanks.

I agree with markdc though, I am seeing errors in the Watchdog like this...

InvalidArgumentException: Route required in Drupal\Core\Url::fromRouteMatch() (line 167 of /home/<...>/public_html/core/lib/Drupal/Core/Url.php)
#0 /home/<...>/public_html/modules/link_trail_by_path/link_trail_by_path.module(51): Drupal\Core\Url::fromRouteMatch(Object(Drupal\Core\Routing\CurrentRouteMatch))
#1 /home/<...>/public_html/core/lib/Drupal/Core/Theme/ThemeManager.php(287): link_trail_by_path_preprocess_links(Array, 'links', Array)
#2 /home/<...>/public_html/core/lib/Drupal/Core/Render/Renderer.php(431): Drupal\Core\Theme\ThemeManager->render('links', Array)
#3 /home/<...>/public_html/core/lib/Drupal/Core/Render/Renderer.php(200): Drupal\Core\Render\Renderer->doRender(Array, true)
#4 /home/<...>/public_html/core/lib/Drupal/Core/Render/Renderer.php(156): Drupal\Core\Render\Renderer->render(Array, true)
#5 /home/<...>/public_html/core/lib/Drupal/Core/Render/Renderer.php(573): Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}()
#6 /home/<...>/public_html/core/lib/Drupal/Core/Render/Renderer.php(157): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#7 /home/<...>/public_html/core/lib/Drupal/Core/Render/Renderer.php(171): Drupal\Core\Render\Renderer->renderPlain(Array)
#8 /home/<...>/public_html/core/modules/big_pipe/src/Render/BigPipe.php(693): Drupal\Core\Render\Renderer->renderPlaceholder('callback=user.t...', Array)
#9 /home/<...>/public_html/core/modules/big_pipe/src/Render/BigPipe.php(547): Drupal\big_pipe\Render\BigPipe->renderPlaceholder('callback=user.t...', Array)
#10 /home/<...>/public_html/core/modules/big_pipe/src/Render/BigPipe.php(305): Drupal\big_pipe\Render\BigPipe->sendPlaceholders(Array, Array, Object(Drupal\Core\Asset\AttachedAssets))
#11 /home/<...>/public_html/core/modules/big_pipe/src/Render/BigPipeResponse.php(112): Drupal\big_pipe\Render\BigPipe->sendContent(Object(Drupal\big_pipe\Render\BigPipeResponse))
#12 /home/<...>/public_html/vendor/symfony/http-foundation/Response.php(374): Drupal\big_pipe\Render\BigPipeResponse->sendContent()
#13 /home/<...>/public_html/index.php(20): Symfony\Component\HttpFoundation\Response->send()
#14 {main}
caldenjacobs’s picture

Title: Status (doesn't work) for drupal 8? » Link Trail by Path not working on Views with caching enabled
Issue summary: View changes
Status: Postponed (maintainer needs more info) » Active
Related issues: +#3186839: User error: InvalidArgumentException: Route required

Since it looks like this issue (#2918474) is primarily related to Link Trail by Path not working with Views unless caching is disabled, I'm going to update the title & description to reflect that.

Regarding the log errors (in #8 and #10), I've created a separate issue for the PHP user error: InvalidArgumentException: Route required message we're seeing in site logs using Link Trail by Path. Please see #3186839.

I unfortunately don't have bandwidth to work on these issues, and it looks like the maintainer, Pol, is no longer using Drupal, so this module may need a new maintainer. Pol did mention in the linked issue that he would be willing to help commit patches if the community is able to help out, here.

markwittens’s picture

The problem here is that the view doesn't know it should vary its cache per page. For now I've added a custom hook in a separate module that solves this problem in my project by invalidating the render cache only right after the view with the cache problem has rendered. Completely disabling the views cache will result in a major performance penalty, this will disable only the render cache and only for the view.

/**
 * Implements hook_views_pre_view().
 */
function mymodule_views_pre_view(ViewExecutable $view, $display_id, array &$args) {
  if ($view->id() === '<YOUR VIEW HERE>') {
    $result = \Drupal::database()->select('cache_render')
      ->fields('cache_render', ['cid'])
      ->condition('cid', 'views:fields:<YOUR VIEW HERE>:<YOUR VIEWS DISPLAY ID HERE>%', 'LIKE')
      ->execute()
      ->fetchAllAssoc('cid');
    \Drupal::cache('render')->deleteMultiple(array_keys($result));
  }
}
pol’s picture

Hello,

I'm indeed no more using Drupal but I'm still here to submit things if it's needed.

Please do not submit patches, but create a merge request so I can review it quickly and merge it if necessary.

Thanks!

sirclickalot’s picture

Status: Active » Closed (outdated)

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.