The current $request_path generation relies on global $base_url.
This approach breaks with the OOP and DI pattern of Drupal.
Current code:
global $base_url;
$request_path = urlencode($base_url . $this->currentPath->getPath());
// ...
$build['open_readspeaker_block'] = [
'#theme' => 'open_readspeaker_ui',
'#request_path' => $request_path,
];
We could simply replace that with Url::fromRoute()
$build['open_readspeaker_block'] = [
'#theme' => 'open_readspeaker_ui',
'#request_path' => urlencode(Url::fromRoute('<current>', [], ['absolute' => TRUE])->toString()),
];
In addition to the new code we could remove the DI of the $container->get('path.current') service.
the result is the same as before, but without any "magic" global variable.
Any thoughts?
Comments
Comment #2
sunlixComment #3
sunlixComment #4
sunlixThis patch removes unnecessary
current_pathDI along with template improvements for the ReadSpeaker endpoint query parameter generation.In core, optional parameters will be filtered if they are not set.
Comment #6
sunlix