2007-09-11 17:35:58 +00:00
< ? php
/**
* @ file
2013-01-04 18:29:51 +00:00
* Administration page callbacks for the Book module .
2007-09-11 17:35:58 +00:00
*/
2013-05-02 04:46:53 +00:00
use Drupal\Component\Utility\Crypt ;
2013-03-10 19:05:24 +00:00
use Drupal\Core\Entity\EntityInterface ;
2013-05-25 20:12:45 +00:00
use Drupal\Core\Language\Language ;
2012-04-26 16:44:37 +00:00
2007-09-11 17:35:58 +00:00
/**
2010-04-13 15:23:03 +00:00
* Returns HTML for a book administration form .
*
2013-01-04 18:29:51 +00:00
* @ param array $variables
2010-04-13 15:23:03 +00:00
* An associative array containing :
* - form : A render element representing the form .
2007-09-11 17:35:58 +00:00
*
2013-09-15 06:46:48 +00:00
* @ see \Drupal\book\Form\BookAdminEditForm :: bookAdminTable ()
2010-04-13 15:23:03 +00:00
* @ ingroup themeable
2007-09-11 17:35:58 +00:00
*/
2009-10-09 01:00:08 +00:00
function theme_book_admin_table ( $variables ) {
$form = $variables [ 'form' ];
2007-11-26 16:19:37 +00:00
drupal_add_tabledrag ( 'book-outline' , 'match' , 'parent' , 'book-plid' , 'book-plid' , 'book-mlid' , TRUE , MENU_MAX_DEPTH - 2 );
drupal_add_tabledrag ( 'book-outline' , 'order' , 'sibling' , 'book-weight' );
2012-10-09 19:49:07 +00:00
$header = array ( t ( 'Title' ), t ( 'Weight' ), t ( 'Parent' ), t ( 'Operations' ));
2007-09-11 17:35:58 +00:00
$rows = array ();
$destination = drupal_get_destination ();
2013-09-16 03:58:06 +00:00
$access = \Drupal :: currentUser () -> hasPermission ( 'administer nodes' );
2007-09-11 17:35:58 +00:00
foreach ( element_children ( $form ) as $key ) {
$nid = $form [ $key ][ 'nid' ][ '#value' ];
$href = $form [ $key ][ 'href' ][ '#value' ];
2007-11-26 16:19:37 +00:00
// Add special classes to be used with tabledrag.js.
2009-08-22 14:34:23 +00:00
$form [ $key ][ 'plid' ][ '#attributes' ][ 'class' ] = array ( 'book-plid' );
$form [ $key ][ 'mlid' ][ '#attributes' ][ 'class' ] = array ( 'book-mlid' );
$form [ $key ][ 'weight' ][ '#attributes' ][ 'class' ] = array ( 'book-weight' );
2007-11-26 16:19:37 +00:00
2013-06-14 22:59:22 +00:00
$indentation = array ( '#theme' => 'indentation' , '#size' => $form [ $key ][ 'depth' ][ '#value' ] - 2 );
2007-10-15 19:33:27 +00:00
$data = array (
2013-06-14 22:59:22 +00:00
drupal_render ( $indentation ) . drupal_render ( $form [ $key ][ 'title' ]),
2007-09-11 17:35:58 +00:00
drupal_render ( $form [ $key ][ 'weight' ]),
2007-11-26 16:19:37 +00:00
drupal_render ( $form [ $key ][ 'plid' ]) . drupal_render ( $form [ $key ][ 'mlid' ]),
2012-10-09 19:49:07 +00:00
);
$links = array ();
$links [ 'view' ] = array (
2013-02-27 22:43:00 +00:00
'title' => t ( 'View' ),
2012-10-09 19:49:07 +00:00
'href' => $href ,
);
if ( $access ) {
$links [ 'edit' ] = array (
2013-02-27 22:43:00 +00:00
'title' => t ( 'Edit' ),
2013-11-15 13:09:50 +00:00
'route_name' => 'node.page_edit' ,
'route_parameters' => array ( 'node' => $nid ),
2012-10-09 19:49:07 +00:00
'query' => $destination ,
);
$links [ 'delete' ] = array (
2013-02-27 22:43:00 +00:00
'title' => t ( 'Delete' ),
2013-11-15 13:09:50 +00:00
'route_name' => 'node.delete_confirm' ,
'route_parameters' => array ( 'node' => $nid ),
2012-10-09 19:49:07 +00:00
'query' => $destination ,
);
}
$data [] = array (
'data' => array (
'#type' => 'operations' ,
'#links' => $links ,
),
2007-09-11 17:35:58 +00:00
);
2007-10-15 19:33:27 +00:00
$row = array ( 'data' => $data );
if ( isset ( $form [ $key ][ '#attributes' ])) {
$row = array_merge ( $row , $form [ $key ][ '#attributes' ]);
}
2009-08-22 14:34:23 +00:00
$row [ 'class' ][] = 'draggable' ;
2007-10-15 19:33:27 +00:00
$rows [] = $row ;
2007-09-11 17:35:58 +00:00
}
2013-06-14 22:59:22 +00:00
$table = array ( '#theme' => 'table' , '#header' => $header , '#rows' => $rows , '#attributes' => array ( 'id' => 'book-outline' ), '#empty' => t ( 'No book content available.' ));
return drupal_render ( $table );
2007-10-15 19:33:27 +00:00
}