If you want to path alias in drupal 8 then we have different syntax in drupal 8, Please follow this.
Syntax:
$alias = \Drupal::service('path.alias_manager')->getAliasByPath($tid or $nid);
Example: like if we have taxonomy term and we want to path alias so first we create URL path as given exmaple..
$tid = '/taxonomy/term/'.$term_id;
$alias = \Drupal::service('path.alias_manager')->getAliasByPath($tid); or \Drupal::service('path.alias_manager')->getAliasByPath('/taxonomy/term/'.$term_id),
OR
$nid = '/node/'.$node_id;
$alias = \Drupal::service('path.alias_manager')->getAliasByPath($nid); or \Drupal::service('path.alias_manager')->getAliasByPath('/node/'.$node_id),
Simple then we can use this alias to send or redirect using
$response = new Symfony\Component\HttpFoundation\RedirectResponse($alias);
$response->send();
return;
Note: If have any suggestions or issue regarding 'How we can Url Alias in Drupal 8?' then you can ask by comments.
Syntax:
$alias = \Drupal::service('path.alias_manager')->getAliasByPath($tid or $nid);
Example: like if we have taxonomy term and we want to path alias so first we create URL path as given exmaple..
$tid = '/taxonomy/term/'.$term_id;
$alias = \Drupal::service('path.alias_manager')->getAliasByPath($tid); or \Drupal::service('path.alias_manager')->getAliasByPath('/taxonomy/term/'.$term_id),
OR
$nid = '/node/'.$node_id;
$alias = \Drupal::service('path.alias_manager')->getAliasByPath($nid); or \Drupal::service('path.alias_manager')->getAliasByPath('/node/'.$node_id),
Simple then we can use this alias to send or redirect using
$response = new Symfony\Component\HttpFoundation\RedirectResponse($alias);
$response->send();
return;
Note: If have any suggestions or issue regarding 'How we can Url Alias in Drupal 8?' then you can ask by comments.
No comments:
Post a Comment