2007-08-20 07:03:08 +00:00
< ? php
/**
* @ file
2011-11-28 11:44:25 +00:00
* Callbacks for adding , editing , and deleting content and managing revisions .
*
* Also includes validation , submission and other helper functions .
*
* @ see node_menu ()
2007-08-20 07:03:08 +00:00
*/
2013-03-10 19:05:24 +00:00
use Drupal\Core\Entity\EntityInterface ;
Issue #1668866 by ParisLiakos, aspilicious, tim.plunkett, pdrake, g.oechsler, dawehner, Berdir, corvus_ch, damiankloip, disasm, marcingy, neclimdul: Replace drupal_goto() with RedirectResponse.
2013-06-19 16:07:30 +00:00
use Symfony\Component\HttpFoundation\RedirectResponse ;
2013-08-16 17:13:11 +00:00
use Drupal\node\NodeInterface ;
2007-08-20 07:03:08 +00:00
2007-12-06 09:58:34 +00:00
/**
2010-04-13 15:23:03 +00:00
* Returns HTML for a list of available node types for node creation .
*
* @ param $variables
* An associative array containing :
* - content : An array of content types .
2007-12-06 09:58:34 +00:00
*
2011-11-28 11:44:25 +00:00
* @ see node_add_page ()
2012-10-04 16:41:38 +00:00
*
2007-12-06 09:58:34 +00:00
* @ ingroup themeable
*/
2009-10-09 01:00:08 +00:00
function theme_node_add_list ( $variables ) {
$content = $variables [ 'content' ];
2007-08-20 07:03:08 +00:00
if ( $content ) {
$output = '<dl class="node-type-list">' ;
2012-05-14 02:50:42 +00:00
foreach ( $content as $type ) {
$output .= '<dt>' . l ( $type -> name , 'node/add/' . $type -> type ) . '</dt>' ;
$output .= '<dd>' . filter_xss_admin ( $type -> description ) . '</dd>' ;
2007-08-20 07:03:08 +00:00
}
$output .= '</dl>' ;
}
2009-08-04 06:44:48 +00:00
else {
2010-01-09 23:03:22 +00:00
$output = '<p>' . t ( 'You have not created any content types yet. Go to the <a href="@create-content">content type creation page</a> to add a new content type.' , array ( '@create-content' => url ( 'admin/structure/types/add' ))) . '</p>' ;
2009-08-04 06:44:48 +00:00
}
2007-08-20 07:03:08 +00:00
return $output ;
}
/**
2011-11-28 11:44:25 +00:00
* Generates a node preview .
*
2013-03-10 19:05:24 +00:00
* @ param \Drupal\Core\Entity\EntityInterface $node
2011-11-28 11:44:25 +00:00
* The node to preview .
*
* @ return
2012-10-04 16:41:38 +00:00
* An HTML - formatted string of a node preview .
2011-11-28 11:44:25 +00:00
*
* @ see node_form_build_preview ()
2007-08-20 07:03:08 +00:00
*/
2013-11-23 20:57:04 +00:00
function node_preview ( NodeInterface $node , array & $form_state ) {
2013-12-01 12:33:39 +00:00
if ( $node -> access ( 'create' ) || $node -> access ( 'update' )) {
2007-08-20 07:03:08 +00:00
2008-09-17 07:11:59 +00:00
$node -> changed = REQUEST_TIME ;
2007-08-20 07:03:08 +00:00
2008-01-29 11:08:17 +00:00
// Display a preview of the node.
2013-11-23 20:57:04 +00:00
if ( ! form_get_errors ( $form_state )) {
2010-07-30 03:06:18 +00:00
$node -> in_preview = TRUE ;
2013-06-10 10:12:28 +00:00
$node_preview = array (
'#theme' => 'node_preview' ,
'#node' => $node ,
);
$output = drupal_render ( $node_preview );
2010-07-30 03:06:18 +00:00
unset ( $node -> in_preview );
2007-08-20 07:03:08 +00:00
}
return $output ;
}
}
/**
2010-04-13 15:23:03 +00:00
* Returns HTML for a node preview for display during node creation and editing .
2007-08-20 07:03:08 +00:00
*
2009-10-09 01:00:08 +00:00
* @ param $variables
* An associative array containing :
2012-04-26 16:44:37 +00:00
* - node : The node entity which is being previewed .
2007-12-06 09:58:34 +00:00
*
2012-08-16 11:30:43 +00:00
* @ see NodeFormController :: preview ()
2012-11-10 15:25:19 +00:00
* @ see node_preview ()
2012-10-04 16:41:38 +00:00
*
2007-12-06 09:58:34 +00:00
* @ ingroup themeable
2007-08-20 07:03:08 +00:00
*/
2009-10-09 01:00:08 +00:00
function theme_node_preview ( $variables ) {
$node = $variables [ 'node' ];
2012-03-01 01:03:30 +00:00
$output = '' ;
2008-01-10 15:57:10 +00:00
2012-12-28 23:03:17 +00:00
$elements = node_view ( $node , 'teaser' );
2012-10-30 02:15:21 +00:00
$elements [ '#attached' ][ 'library' ][] = array ( 'node' , 'drupal.node.preview' );
2010-04-11 18:33:44 +00:00
$trimmed = drupal_render ( $elements );
$elements = node_view ( $node , 'full' );
$full = drupal_render ( $elements );
2009-06-12 08:39:40 +00:00
// Do we need to preview trimmed version of post as well as full version?
if ( $trimmed != $full ) {
2007-08-20 07:03:08 +00:00
drupal_set_message ( t ( 'The trimmed version of your post shows what your post looks like when promoted to the main page or when exported for syndication.<span class="no-js"> You can insert the delimiter "<!--break-->" (without the quotes) to fine-tune where your post gets split.</span>' ));
2008-04-14 17:48:46 +00:00
$output .= '<h3>' . t ( 'Preview trimmed version' ) . '</h3>' ;
2009-06-12 08:39:40 +00:00
$output .= $trimmed ;
2008-04-14 17:48:46 +00:00
$output .= '<h3>' . t ( 'Preview full version' ) . '</h3>' ;
2009-06-12 08:39:40 +00:00
$output .= $full ;
2007-08-20 07:03:08 +00:00
}
else {
2009-06-12 08:39:40 +00:00
$output .= $full ;
2007-08-20 07:03:08 +00:00
}
return $output ;
}
/**
2011-11-28 11:44:25 +00:00
* Page callback : Generates an overview table of older revisions of a node .
*
2012-10-04 16:41:38 +00:00
* @ param object $node
* A node object .
*
* @ return array
* An array as expected by drupal_render () .
*
2011-11-28 11:44:25 +00:00
* @ see node_menu ()
2013-09-18 18:30:30 +00:00
*
* @ deprecated Use \Drupal\node\Controller\NodeController :: revisionOverview ()
2007-08-20 07:03:08 +00:00
*/
2009-11-08 10:02:41 +00:00
function node_revision_overview ( $node ) {
2013-11-28 07:44:52 +00:00
$build [ '#title' ] = t ( 'Revisions for %title' , array ( '%title' => $node -> label ()));
2007-08-20 07:03:08 +00:00
2012-10-09 19:49:07 +00:00
$header = array ( t ( 'Revision' ), t ( 'Operations' ));
2007-08-20 07:03:08 +00:00
$revisions = node_revision_list ( $node );
$rows = array ();
2013-08-16 17:13:11 +00:00
$type = $node -> getType ();
2012-11-29 07:28:47 +00:00
2007-08-20 07:03:08 +00:00
$revert_permission = FALSE ;
2013-12-01 12:33:39 +00:00
if (( user_access ( " revert $type revisions " ) || user_access ( 'revert all revisions' ) || user_access ( 'administer nodes' )) && $node -> access ( 'update' )) {
2007-08-20 07:03:08 +00:00
$revert_permission = TRUE ;
}
$delete_permission = FALSE ;
2013-12-01 12:33:39 +00:00
if (( user_access ( " delete $type revisions " ) || user_access ( 'delete all revisions' ) || user_access ( 'administer nodes' )) && $node -> access ( 'delete' )) {
2007-08-20 07:03:08 +00:00
$delete_permission = TRUE ;
}
foreach ( $revisions as $revision ) {
$row = array ();
if ( $revision -> current_vid > 0 ) {
2013-06-10 10:12:28 +00:00
$username = array (
'#theme' => 'username' ,
2013-07-09 13:46:44 +00:00
'#account' => user_load ( $revision -> uid ),
2013-06-10 10:12:28 +00:00
);
2013-07-20 12:21:43 +00:00
$row [] = array ( 'data' => t ( '!date by !username' , array ( '!date' => l ( format_date ( $revision -> revision_timestamp , 'short' ), 'node/' . $node -> id ()), '!username' => drupal_render ( $username )))
2008-04-14 17:48:46 +00:00
. (( $revision -> log != '' ) ? '<p class="revision-log">' . filter_xss ( $revision -> log ) . '</p>' : '' ),
2009-08-22 14:34:23 +00:00
'class' => array ( 'revision-current' ));
2012-10-09 19:49:07 +00:00
$row [] = array ( 'data' => drupal_placeholder ( t ( 'current revision' )), 'class' => array ( 'revision-current' ));
2007-08-20 07:03:08 +00:00
}
else {
2013-06-10 10:12:28 +00:00
$username = array (
'#theme' => 'username' ,
2013-07-09 13:46:44 +00:00
'#account' => user_load ( $revision -> uid ),
2013-06-10 10:12:28 +00:00
);
2013-08-16 17:13:11 +00:00
$row [] = t ( '!date by !username' , array ( '!date' => l ( format_date ( $revision -> revision_timestamp , 'short' ), " node/ " . $node -> id () . " /revisions/ " . $revision -> vid . " /view " ), '!username' => drupal_render ( $username )))
2008-04-14 17:48:46 +00:00
. (( $revision -> log != '' ) ? '<p class="revision-log">' . filter_xss ( $revision -> log ) . '</p>' : '' );
2007-08-20 07:03:08 +00:00
if ( $revert_permission ) {
2012-10-09 19:49:07 +00:00
$links [ 'revert' ] = array (
2013-02-15 02:53:23 +00:00
'title' => t ( 'Revert' ),
2013-08-16 17:13:11 +00:00
'href' => " node/ " . $node -> id () . " /revisions/ " . $revision -> vid . " /revert " ,
2012-10-09 19:49:07 +00:00
);
2007-08-20 07:03:08 +00:00
}
if ( $delete_permission ) {
2012-10-09 19:49:07 +00:00
$links [ 'delete' ] = array (
2013-02-15 02:53:23 +00:00
'title' => t ( 'Delete' ),
2013-08-16 17:13:11 +00:00
'href' => " node/ " . $node -> id () . " /revisions/ " . $revision -> vid . " /delete " ,
2012-10-09 19:49:07 +00:00
);
2007-08-20 07:03:08 +00:00
}
2012-10-09 19:49:07 +00:00
$row [] = array (
'data' => array (
'#type' => 'operations' ,
'#links' => $links ,
),
);
2007-08-20 07:03:08 +00:00
}
2012-10-09 19:49:07 +00:00
$rows [] = $row ;
2007-08-20 07:03:08 +00:00
}
2009-12-28 11:12:55 +00:00
2009-07-29 06:39:35 +00:00
$build [ 'node_revisions_table' ] = array (
'#theme' => 'table' ,
'#rows' => $rows ,
'#header' => $header ,
2012-03-01 01:03:30 +00:00
'#attached' => array (
2013-06-07 10:48:55 +00:00
'css' => array ( drupal_get_path ( 'module' , 'node' ) . '/css/node.admin.css' ),
2012-03-01 01:03:30 +00:00
),
2009-07-29 06:39:35 +00:00
);
2007-08-20 07:03:08 +00:00
2009-07-29 06:39:35 +00:00
return $build ;
2007-08-20 07:03:08 +00:00
}