- π¬π§United Kingdom catch
Retitling however I'm not sure this is the right place to do this.
Does the
Url
class not handle this already for example using ::fromUri() and then ::toString()? - πΊπΈUnited States itmaybejj
This stumped me on Editoria11y. I'm currently doing this wildly inelegant thing to get the true alias:
$page_path = \Drupal::service('path_alias.manager')->getAliasByPath('/node/' . $nid, $language); $lang_check = Url::fromRoute('<current>')->toString(); if ($language && str_starts_with($lang_check, '/' . $language . '/') && !str_starts_with($page_path, '/' . $language . '/')) { $page_path = '/' . $language . $page_path; }
The alias manager will get me the "nice" alias...but not reliably language prefix. Url::fromRoute will get me the prefix, but not the nice alias. So I have been running both queries and prefixing as needed.