Score:0

How do I add a custom URL for node/add/{custom-content-type}?

th flag

I have a custom content type which I fill up with the help of the Forms Steps module.

I want to set custom URL for node/add/{custom-content-type}. I tried using a route subscriber and the following code.

/**
 * {@inheritdoc}
 */
protected function alterRoutes(RouteCollection $collection) { 
  if ($route = $collection->get('node.add_page')) {
    $current_uri = \Drupal::request()->getRequestUri();
    if ($current_uri == "node/add/custom-content-type") {
      $route->setPath('/Custom-content/add');
    }
  }
}

The above code is not changing the URL. I am finding difficult to change the URL only for the custom content type.

How can I achieve it?

Jaypan avatar
de flag
This can be done, but it would be easier to enable the path module and redirect module, and create an alias and a redirect to that alias.
leymannx avatar
ne flag
Does this answer your question? [How to create URL alias for node edit page](https://drupal.stackexchange.com/questions/273938/how-to-create-url-alias-for-node-edit-page)
apaderno avatar
us flag
Is there any good reason to change from node/add/[content-type] to [content-type]/add for a single content type? The reason why Drupal uses node/add/[content-type] is to avoid conflicts with other routes defined from third-party modules. Also, a placeholder cannot be the first part in the route path; the first part of a route path can only be a static string, like `'node'`.
apaderno avatar
us flag
The question doesn't make clear if there is any need to programmatically do what the question describes. I still think it's a bad idea, but if I were to do it, I would do it as @Jaypan described.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.