0

How can I get current country pathPrefix in D8 ?

I know drupalSettings.path.pathPrefix gives that in JS, but how can I get it in preprocess hook ?

Following gives only the path alias, but without pathPrefix.

\Drupal::service('path.alias_manager')->getAliasByPath('/node/'.$nid[0]);
0

You can call PathProcessorManager::processOutbound() for the internal path and you get the path alias and the prefix at the same time:

$options = ['prefix' => ''];
$path = \Drupal::service('path_processor_manager')->processOutbound('/node/1', $options);
$prefix = $options['prefix'];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.