Url::__toString() was removed from core recently, breaking devel_silent().

Comments

willzyx’s picture

I'm just thinking out loud

 function devel_silent() {
   // Don't interfere with private files/images.
  $request_path = Url::fromRoute('<current>');

Simply change it in Url::fromRoute('<current>')->toString() is not an option because if the drupal installation is in a subfolder not work.
Url::fromRoute('<current>')->getInternalPath() might work but is deprecated.

I was thinking something like

function devel_silent() {
  $route_name = \Drupal::routeMatch()->getRouteName();

  $excluded_routes = array(
    'file.ajax_progress',
    'file.ajax_upload',
    'image.style_private',
    'system.batch_page.html',
    'system.batch_page.json',
    'system.files',
    'system.private_file_download',
  );

  return
    (PHP_SAPI === 'cli') ||
    (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'ApacheBench') !== FALSE) ||
    !empty($_REQUEST['XDEBUG_PROFILE']) ||
    isset($GLOBALS['devel_shutdown']) ||
    in_array($route_name, $excluded_routes);
}

but I'm not sure whether it is the best way to handle it

tstoeckler’s picture

Simply change it in Url::fromRoute('')->toString() is not an option because if the drupal installation is in a subfolder not work.

Not sure about this statement, as that was the previous (implicit) behavior. So if there's a problem with it that seems like a separate issue?

willzyx’s picture

Yes the statement is not entirely correct.. with the currently implementation Url::fromRoute('')->toString() doesn't work at all (even before #2416971: Remove Url::__toString() with implicit behavior) because the returned path has a leading slash (and if your site run in a subfolder the returned path is base_path + internal_path)

so we can commit the change that you suggest and only fix warnings or find a solution that makes work properly devel_silent()..
help is appreciated :)

  • willzyx committed 77f615e on 8.x-1.x
    Issue #2445309: substr() expects parameter 1 to be string, object given...
willzyx’s picture

Status: Active » Fixed

Since this issue is blocking the test bot and @tstoeckler in #2 was right, the suggested solution was committed as temporary solution and i opened #2448391: devel_silent() doesn't work properly

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.