Problem/Motivation
Follow-up to #1088112: Introduce a token to get site's base URL
Steps to reproduce:
- Go to your installed drupal directory and append
index.php
(e.g http://drupal.test/index.php) - Build a URL with
base
prefix:Url::fromUri('base:sites/default/files/og_image.jpg')
- Assert the URL to the image asset is broken as the path is
/index.php/sites/default/files/og_image.jpg
Proposed resolution
When building a URL with base
prefix use $request->getBasePath()
instead of $request->getBaseUrl()
which results in omitting index.php
in case it is present.