The following code from the "example.module" will help you to add the cancel button to any node form.
How to set the page title in Drupal 8? drupal_set_title() in Drupal 8 ? drupal_get_title() in Drupal8?
Using the following lines of code in hook_form_alter() , able to set the title and get the title after saving the code do CLEAR CACHE drupal_set_title() in Drupal8 $request = \ Drupal :: request (); if ( $route = $request -> attributes -> get (\ Symfony \ Cmf \ Component \ Routing \ RouteObjectInterface :: ROUTE_OBJECT )) { $route -> setDefault ( '_title' , 'New Title' ); } drupal_get_title() in Drupal8 $request = \ Drupal :: request (); if ( $route = $request -> attributes -> get (\ Symfony \ Cmf \ Component \ Routing \ RouteObjectInterface :: ROUTE_OBJECT )) { $title = \ Drupal :: service ( 'title_resolver' ) -> getTitle ( $request , $route ); }
Really helpful. Thank you. I an getting
ReplyDeleteNotice: Undefined index: destination in example_form_cancel().
Do you know why??
You can use isset() to avoid the notice, like this:
ReplyDelete$url = isset($_GET['destination']) ? $_GET['destination'] : 'choose/your/path';