Hi,

I want use a token join-path but with an offset for skip one or more elements.

Example on a multisite (with micro site) with book module, book by site, default pattern [node:book:parents:join-path/[node:title], but i want [node:book:parents:join-path-offset:1/[node:title] for skip the first element.

Regards

Comments

netsliver created an issue. See original summary.

netsliver’s picture

Project: Token » Pathauto

Sorry I move this issue on pathauto

berdir’s picture

Category: Feature request » Support request

Might be easier to just implement your own token that does that, you just need to duplicate the hooks in pathauto.tokens.inc or find a way to pass it through your token on to join-path, e.g. parents:offset:1:join-path

Seems to specific for a generic feature unless others are interested too.

netsliver’s picture

Status: Active » Needs review
StatusFileSize
new1.99 KB

Path attached :)

netsliver’s picture

Problem with my patch, the slash / is removed from the replacement although there is the implode!?!?

berdir’s picture

pathauto has a setting to control which token-parts indicate a URL-safe token, you need to extend that.

netsliver’s picture

StatusFileSize
new2.6 KB

Ok with the safe-token updated it works!

netsliver’s picture

Yes I thought of the parameter just after ... I posted too quickly

netsliver’s picture

StatusFileSize
new2.66 KB

patch with last dev version which replace render by service renderer

berdir’s picture

Status: Needs review » Needs work
+++ b/pathauto.tokens.inc
@@ -30,17 +36,26 @@ function pathauto_tokens($type, $tokens, array $data, array $options, Bubbleable
 
+    $offset = 0;
+    if ($join_path_offset = \Drupal::token()->findWithPrefix($tokens, 'join-path-offset')) {
+      $offset = key($join_path_offset);
+    }

this assumes that there's only a single token.

I'm not sure this is the best approach, nor whether this needs to be in this module.

I would probably implement this as a chained token, which will _not_ require config changes, something like this:

[node:something-that-returns-an-array:shift:join-path] (after array_shift()).

That avoids the need for a second dynamic argument, and if you need to cut off more than one you can chain it: shift:shift:join-path. Far simpler to implement.

You could implement such a token in a custom module. For it to live in pathauto or token, it will require test coverage.

paul_serval’s picture

StatusFileSize
new2.78 KB

Reroll patch

mably’s picture

Status: Needs work » Closed (won't fix)

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

paul_serval’s picture

StatusFileSize
new2.77 KB

Reroll patch