X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fpathauto%2Fpathauto.tokens.inc;fp=web%2Fmodules%2Fcontrib%2Fpathauto%2Fpathauto.tokens.inc;h=626ff09c573e2030397b429a6f4db9ee11bd6af0;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/modules/contrib/pathauto/pathauto.tokens.inc b/web/modules/contrib/pathauto/pathauto.tokens.inc new file mode 100644 index 000000000..626ff09c5 --- /dev/null +++ b/web/modules/contrib/pathauto/pathauto.tokens.inc @@ -0,0 +1,49 @@ + t('Joined path'), + 'description' => t('The array values each cleaned by Pathauto and then joined with the slash into a string that resembles an URL.'), + ); + + return $info; +} + +/** + * Implements 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; +}