2

So I need to create links to specific translations of a node but am having issues.

This is my code:

foreach($entities as $entity) {
$urls[] = Url::fromRoute('entity.node.canonical', [
        'node' => $entity->id(),
        'language' => $entity->language()->getId(),
      ]);
}

$entity in this context is EntityInterface.

But this gives me /node/1185?language=es instead of /es/node/1185.

1

1 Answer 1

2

$entity->toUrl('canonical', ['language' => $entity->language()]);

Taken from this question thread

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.