2007-09-11 17:35:58 +00:00
< ? php
/**
* @ file
* User page callbacks for the book module .
*/
2013-03-10 19:05:24 +00:00
use Drupal\Core\Entity\EntityInterface ;
2012-06-04 12:06:09 +00:00
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException ;
2012-06-02 19:41:40 +00:00
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException ;
2012-04-26 16:44:37 +00:00
2007-09-11 17:35:58 +00:00
/**
2011-12-13 03:13:23 +00:00
* Form constructor to confirm removal of a node from a book .
2007-09-11 17:35:58 +00:00
*
2013-03-10 19:05:24 +00:00
* @ param \Drupal\Core\Entity\EntityInterface $node
2011-12-13 03:13:23 +00:00
* The node to delete .
2007-09-11 17:35:58 +00:00
*
2011-12-13 03:13:23 +00:00
* @ see book_remove_form_submit ()
* @ see book_menu ()
2007-09-11 17:35:58 +00:00
* @ ingroup forms
2013-09-21 11:42:43 +00:00
*
* @ deprecated Use \Drupal\book\Form\BookForm :: remove ()
2007-09-11 17:35:58 +00:00
*/
2013-03-10 19:05:24 +00:00
function book_remove_form ( $form , & $form_state , EntityInterface $node ) {
2007-09-11 17:35:58 +00:00
$form [ '#node' ] = $node ;
2012-07-22 18:07:00 +00:00
$title = array ( '%title' => $node -> label ());
2007-09-11 17:35:58 +00:00
if ( $node -> book [ 'has_children' ]) {
$description = t ( '%title has associated child pages, which will be relocated automatically to maintain their connection to the book. To recreate the hierarchy (as it was before removing this page), %title may be added again using the Outline tab, and each of its former child pages will need to be relocated manually.' , $title );
}
else {
$description = t ( '%title may be added to hierarchy again using the Outline tab.' , $title );
}
2013-07-20 12:21:43 +00:00
return confirm_form ( $form , t ( 'Are you sure you want to remove %title from the book hierarchy?' , $title ), 'node/' . $node -> id (), $description , t ( 'Remove' ));
2007-09-11 17:35:58 +00:00
}
/**
2011-12-13 03:13:23 +00:00
* Form submission handler for book_remove_form () .
2007-09-11 17:35:58 +00:00
*/
function book_remove_form_submit ( $form , & $form_state ) {
$node = $form [ '#node' ];
2013-09-16 03:58:06 +00:00
if ( \Drupal :: service ( 'book.manager' ) -> checkNodeIsRemovable ( $node )) {
2007-09-11 17:35:58 +00:00
menu_link_delete ( $node -> book [ 'mlid' ]);
2008-11-16 15:02:45 +00:00
db_delete ( 'book' )
2013-07-20 12:21:43 +00:00
-> condition ( 'nid' , $node -> id ())
2008-11-16 15:02:45 +00:00
-> execute ();
2007-09-11 17:35:58 +00:00
drupal_set_message ( t ( 'The post has been removed from the book.' ));
}
2013-11-14 05:31:49 +00:00
$form_state [ 'redirect_route' ] = array (
'route_name' => 'node.view' ,
'route_parameters' => array (
'node' => $node -> id (),
),
);
2007-09-11 17:35:58 +00:00
}