0

I have seen this post: where does $data come from in hook_tokens?, but that did not help me answer my question, maybe it could've but there's no way for me to interact with that post.

I am working in Drupal 8.5, using pathauto 8.x-1.1.

I am looking at pathauto.tokens.inc, here is the code for pathauto's hook_tokens():

function pathauto_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
  $replacements = array();

  if ($type == 'array' && !empty($data['array'])) {
    $array = $data['array'];

    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'join-path':
          $values = array();
          foreach (token_element_children($array) as $key) {
            $value = is_array($array[$key]) ? render($array[$key]) : (string) $array[$key];
            $value = \Drupal::service('pathauto.alias_cleaner')->cleanString($value, $options);
            $values[] = $value;
          }
          $replacements[$original] = implode('/', $values);
          break;
      }
    }
  }

  return $replacements;
}

I can't seem to find how the menu trail makes it into the $data parameter. I can see the menu trail in $data when I set a breakpoint at array = data['array'].

My ultimate goal is to figure out why pages with a menu_position rule associated with them are not getting the joined-path history in their url alias.

  • 3
    Welcome to Drupal Answer! You shouldn't take any of the template comments about "not an answer" personally. DA isn't a forum so the volunteer admins are trying to enforce the Q&A rules here. The goal is promote short & direct answers, not a chain of "me too" posts, hence the comments about duplicates, vague, or non-answers. – Shawn Conn Mar 24 '18 at 16:55
0

Token resolving is recursive. The caller of replace() is responsible for providing the data.

As far as this token is considered, it's not an active trail, it's just an array with strings that is combined together.

Your token probably looks something like [node:menu-link:parents:join-path]. If this doesn't receive the right parents then you need to look at where the parents are fetched and passed on, which is in token.module: https://cgit.drupalcode.org/token/tree/token.tokens.inc#n721

And if it is a different token then you need to look up whatever intermediate tokens you are using

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.