Sub-directory installation support for routes.

Created on 28 September 2023, 9 months ago
Updated 6 November 2023, 8 months ago

Problem/Motivation

For sub-directory multi-site installation with paths like /site1/en/node/1, /site2/de/node/2 etc we have following issue:
1. route(path: "/site1/en/node/1") query returns empty result
2. route field in menu queries is empty
Example

menu(name: MAIN) {
    items {
      title
      url
      children {
        title
        url
        route {
          ... on RouteInternal {
            entity {
              ... on NodePage {
                title
                id
              }
            }
          }
        }
      }
    }
  }
{
  "data": {
    "menu": {
      "items": [
        {
          "title": "Page 1",
          "url": "/site1/en/node/466",
          "children": [
            {
              "title": "Page 2",
              "url": "/site1/en/node/467",
              "route": null
              }
            }
          ]
        }
      ]
    }
  }
}

Problem seems to be in url_or_redirect processor at

// Convert path string to a url.
$url = $this->pathValidator->getUrlIfValidWithoutAccessCheck($path);

This seems to not support paths with directory prefix.

Proposed resolution

Use this hook in custom module as workaround

/**
 * Implements hook_graphql_compose_routes_incoming_alter().
 */
function mymodule_graphql_compose_routes_incoming_alter(&$path) {
  $base_path = \Drupal::request()->getBasePath();
  if ($base_path && strpos($path, $base_path) === 0) {
    $path = substr($path, strlen($base_path));
  }
}

or implement similar logic in url_or_redirect.

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡§πŸ‡ΎBelarus Yury N

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

Comments & Activities

Production build 0.69.0 2024