Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 294099

\Drupal\Core\Url does not accept root-relative (file) URLs, making it impossible to let LinkGenerator create root-relative file URL links

$
0
0

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.


Viewing all articles
Browse latest Browse all 294099

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>