Problem/Motivation
Examples:
template_preprocess_file_link()
\Drupal\file\Plugin\Field\FieldFormatter\BaseFieldFileFormatterBase::viewElements()
\Drupal\file\Plugin\Field\FieldFormatter\FileUriFormatter::viewValue()
- …
These all generate links (<a href="…"></a>
) using LinkGenerator
/\Drupal\Core\Link
, which in turn require \Drupal\Core\Url
objects.
Those \Drupal\Core\Url
objects require a URL scheme. Which means root-relative (file) URLs cannot be passed to them, which means we must generate absolute file URLs, which means trouble as soon as you encounter sites available over both HTTP and HTTPS.
Proposed resolution
Detect root-relative URLs, automatically use the base:
scheme. This is then similar to what \Drupal\Core\Url::fromUri()
already does for protocol-relative URLs.
Remaining tasks
None.
User interface changes
None.
API changes
No changes; one addition: Url::fromUri()
no longer considers /cat.png
invalid (i.e. as using an invalid URI scheme); instead it detects this as a root-relative URL and hence uses the base:
scheme.
Data model changes
None.