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]); 

1 Answer 1

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']; 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.