From a hook (not form_alter), I want redirect the user to a node edit page (like mywebsite/node/[nid]/edit)
How can I do that with the RedirectResponse
class?
After searches, I found the following code.
new RedirectResponse(\Drupal::url('route.name'));
How can I get/find the route.name for a node edit page?
Update :
According the cilefen's answer =) From my entity_insert hook :
function article_entity_insert(EntityInterface $entity) {
if ($entity->bundle() == "article"){
Url::fromRoute('entity.node.edit_form',['node', $entity->id()]); //But when I create a new node, the "view" page is loaded and not the edit page
dpm($entity->id()); //show the node id
}
}
Update 2 :
The command
dpm(Url::fromRoute('entity.node.edit_form',['node', $entity->id()]));
return
Drupal\Core\Url Object
(
[urlGenerator:protected] =>
[urlAssembler:protected] =>
[accessManager:protected] =>
[routeName:protected] => entity.node.edit_form
[routeParameters:protected] => Array
(
[0] => node
[1] => 31
)
[options:protected] => Array
(
)
[external:protected] =>
[unrouted:protected] =>
[uri:protected] =>
[internalPath:protected] =>
[_serviceIds:protected] => Array
(
)
)
But the command
dpm(Url::fromRoute('entity.node.edit_form',['node', $entity->id()])->toString());
Return this error :
[Mon Feb 15 01:38:30.081002 2016] [:error] [pid 10219] [client 192.168.1.48:49246] Uncaught PHP Exception Drupal\Core\Entity\EntityStorageException: "Some mandatory parameters are missing ("node") to generate a URL for route "entity.node.edit_form"." at /var/www/system/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php line 757, referer: http://192.168.1.44/system/node/add/article