1

With Drupal 8 and Commerce 2.10

I created a php code to display the link of my store.

When I go to the link, it displays:

https://www.domaine.com/shop/name

I want to display without alias:

https://www.domaine.com/store/id

How to do ?

$link = Link::createFromRoute($this->t('my business'), 'entity.commerce_store.canonical', ['commerce_store' => $store_id], ['attributes' => ['target' => '_blank']])->toString();
5

You have to set the option alias:

$link = Link::createFromRoute(
  $this->t('my business'),
  'entity.commerce_store.canonical',
  ['commerce_store' => $store_id],
  ['alias' => TRUE, 'attributes' => ['target' => '_blank']]
)->toString();
  • Thank you, how to add at the end of my link /cgv ? – user90334 Nov 4 '18 at 13:32
  • How is this connected to the question, aliased or not aliased? – 4k4 Nov 4 '18 at 13:45
  • I am with Drupal 8 and there is still the alias. I think adding an element at the end of the url will no longer use the alias. – user90334 Nov 4 '18 at 13:48
  • I just realized that the problem was related to Drupal and the modulehttps://www.drupal.org/project/pathauto. So the only way to get the url /store/3 is to add an item to the end /store/3/cgv this way the url will not be rewritten by Drupal. How to add an item at the end ? – user90334 Nov 4 '18 at 14:08
  • Yes, you could create a second route with the pattern /store/3/cgv and specifiy this route in the link. But I don't think you need to do this. The option added to the link will disable aliasing for the original route and you'll get store/3. Or configure Pathauto to not create an alias for the original route in the first place. – 4k4 Nov 4 '18 at 16:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy