Nodes with redirections without base path breaks breadcrumb construction

Created on 5 February 2024, 5 months ago
Updated 28 February 2024, 4 months ago

The solution introduced on issue #2968082 β†’ creates a bug when we have a different base path (usually on local development environments):

    // Check to see if the path is actually a redirect, if it is, resolve it to
    // its source before we create the request.  Strip the starting slash,
    // redirect module doesn't include it.
    if ($this->moduleHandler->moduleExists('redirect') && $this->config->get(EasyBreadcrumbConstants::FOLLOW_REDIRECTS)) {
      $redirect_path = $path;
      if ($redirect_path[0] === '/') {
        $redirect_path = substr($redirect_path, 1);
      }
      $language_prefix = $this->languageManager->getCurrentLanguage()->getId();
      if (strpos($redirect_path, "$language_prefix/") === 0) {
        $redirect_path = substr($redirect_path, strlen("$language_prefix/"));
      }
      $redirects = \Drupal::service('redirect.repository')
        ->findBySourcePath($redirect_path);
      if (!empty($redirects)) {
        // Take the first redirect if we have multiple, there should normally
        // only be one redirect for a source.
        /** @var \Drupal\redirect\Entity\Redirect $redirect */
        $redirect = current($redirects);
        $path = $redirect->getRedirectUrl()->toString();
      }
    }

When iterating over the path it removes the initial slash and when reconstructing it disconsiders the possibility of different base paths used on local environments for instance, therefore fails silently and the breadcrumb is either not created or created in half.

Steps to reproduce:

  1. Create a node with a path alias and that this alias also have a parent node ex: Home > Events > Event title.
  2. Add redirections to this node starting with a / only as it would be on your production environment.
  3. Enable the "Follow redirects"option on easy breadcrumb settings.
  4. Visit the node the breadcrumb should be either not present or it will not be complete.

I'll leave here a proposition patch to fix this issue.

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium gilmar.lima Brussels

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.69.0 2024