0

This is some code from my theme_menu_link in Drupal 7.

function mytheme_menu_link($variables) {
  $element = $variables['element'];
  if(arg(0) === 'x') {
    if($element['#href'] === '<front>') {
      $element['#href'] = 'x';
    } else {
      $element['#href'] = 'x/' . $element['#href'];
    }
  }

At this point, I just need to do the same thing in Drupal 8: If the visitor arrived at the page with an arg(0) of 'x', then prepend all of the menu links with 'x' keeping them in the "x" experience of the site.

I appreciate any help you can offer. Please provide detail if possible.

marked as duplicate by kenorb, mradcliffe, Yusef Mohamadi, leymannx, Krishna Mohan Dec 12 '18 at 6:57

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • If you want to keep the visitors in the "x" experience on the whole site then you need probably a path processor, see the code example in this topic drupal.stackexchange.com/questions/230171/… – 4k4 Apr 14 '18 at 8:35
  • In Drupal 8, you can use $arg0 = explode('/', \Drupal::service('path.current')->getPath())[1]; instead of arg(0). – kenorb Dec 7 '18 at 11:47

Browse other questions tagged or ask your own question.