When using MetadataBubblingUrlGenerator->generateFromRoute(), UrlGeneratorInterface::ABSOLUTE_URL generates a path, and UrlGeneratorInterface::ABSOLUTE_PATH generates a URL

Created on 20 September 2024, 3 months ago

Problem/Motivation

I've noticed through a custom theme hook implementation that calling the generateFromRoute method of the \Drupal\Core\Render\MetadataBubblingUrlGenerator class with the option ['absolute' => \Symfony\Component\Routing\Generator\UrlGeneratorInterface::ABSOLUTE_URL] generates an absolute path, while the ABSOLUTE_PATH constant of the same interface generates an absolute URL.

This happens everywhere that I utilize the URL generator service and has been very easy to reproduce for me.

Steps to reproduce

Below is an isolated snippet than can reliably reproduce the aforementioned behavior.

/** @var \Drupal\Core\Render\MetadataBubblingUrlGenerator $url_generator */
$url_generator = \Drupal::service('url_generator');

$absolute_url = $url_generator->generateFromRoute(
  'entity.node.canonical',
  ['node' => 1],
  ['absolute' => $url_generator::ABSOLUTE_URL],
  TRUE
);

echo ($absolute_url->getGeneratedUrl());
// Output: /node/1

$absolute_path = $url_generator->generateFromRoute(
  'entity.node.canonical',
  ['node' => 1],
  ['absolute' => $url_generator::ABSOLUTE_PATH],
  TRUE
);

echo ($absolute_path->getGeneratedUrl());
// Output: http://example.com/node/1
πŸ› Bug report
Status

Active

Version

10.3 ✨

Component
RoutingΒ  β†’

Last updated 2 days ago

Created by

πŸ‡ΊπŸ‡ΈUnited States FrankieD3

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

Comments & Activities

Production build 0.71.5 2024