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
*/
2014-04-07 15:01:20 +00:00
use Drupal\Component\Utility\Xss ;
2014-07-31 00:50:42 +00:00
use Drupal\Core\Form\FormStateInterface ;
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
/**
Issue #1987406 by jenlampton, Petr Illek, forbesgraham, herom, jerdavis, Jon Pugh, sanguis, idflood, ezeedub, shanethehat, joelpittet | Cottser: Node.module - Convert theme_ functions to Twig.
2014-02-13 16:54:28 +00:00
* Prepares variables for list of available node type templates .
2010-04-13 15:23:03 +00:00
*
Issue #1987406 by jenlampton, Petr Illek, forbesgraham, herom, jerdavis, Jon Pugh, sanguis, idflood, ezeedub, shanethehat, joelpittet | Cottser: Node.module - Convert theme_ functions to Twig.
2014-02-13 16:54:28 +00:00
* Default template : node - add - list . html . twig .
*
* @ param array $variables
2010-04-13 15:23:03 +00:00
* 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 ()
2007-12-06 09:58:34 +00:00
*/
Issue #1987406 by jenlampton, Petr Illek, forbesgraham, herom, jerdavis, Jon Pugh, sanguis, idflood, ezeedub, shanethehat, joelpittet | Cottser: Node.module - Convert theme_ functions to Twig.
2014-02-13 16:54:28 +00:00
function template_preprocess_node_add_list ( & $variables ) {
$variables [ 'types' ] = array ();
if ( ! empty ( $variables [ 'content' ])) {
foreach ( $variables [ 'content' ] as $type ) {
$variables [ 'types' ][ $type -> type ] = array (
'type' => $type -> type ,
'add_link' => l ( $type -> name , 'node/add/' . $type -> type ),
2014-04-07 15:01:20 +00:00
'description' => Xss :: filterAdmin ( $type -> description ),
Issue #1987406 by jenlampton, Petr Illek, forbesgraham, herom, jerdavis, Jon Pugh, sanguis, idflood, ezeedub, shanethehat, joelpittet | Cottser: Node.module - Convert theme_ functions to Twig.
2014-02-13 16:54:28 +00:00
);
2007-08-20 07:03:08 +00:00
}
2009-08-04 06:44:48 +00:00
}
2007-08-20 07:03:08 +00:00
}
/**
2011-11-28 11:44:25 +00:00
* Generates a node preview .
*
2014-02-07 07:23:07 +00:00
* @ param \Drupal\node\NodeInterface $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
*/
2014-07-31 00:50:42 +00:00
function node_preview ( NodeInterface $node , FormStateInterface $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 ;
}
}
/**
Issue #1987406 by jenlampton, Petr Illek, forbesgraham, herom, jerdavis, Jon Pugh, sanguis, idflood, ezeedub, shanethehat, joelpittet | Cottser: Node.module - Convert theme_ functions to Twig.
2014-02-13 16:54:28 +00:00
* Prepares variables for node preview templates .
2007-08-20 07:03:08 +00:00
*
Issue #1987406 by jenlampton, Petr Illek, forbesgraham, herom, jerdavis, Jon Pugh, sanguis, idflood, ezeedub, shanethehat, joelpittet | Cottser: Node.module - Convert theme_ functions to Twig.
2014-02-13 16:54:28 +00:00
* Default template : node - preview . html . twig .
*
* @ param array $variables
2009-10-09 01:00:08 +00:00
* 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
*
2014-04-25 23:12:39 +00:00
* @ see NodeForm :: preview ()
2012-11-10 15:25:19 +00:00
* @ see node_preview ()
2007-08-20 07:03:08 +00:00
*/
Issue #1987406 by jenlampton, Petr Illek, forbesgraham, herom, jerdavis, Jon Pugh, sanguis, idflood, ezeedub, shanethehat, joelpittet | Cottser: Node.module - Convert theme_ functions to Twig.
2014-02-13 16:54:28 +00:00
function template_preprocess_node_preview ( & $variables ) {
2009-10-09 01:00:08 +00:00
$node = $variables [ 'node' ];
Issue #1987406 by jenlampton, Petr Illek, forbesgraham, herom, jerdavis, Jon Pugh, sanguis, idflood, ezeedub, shanethehat, joelpittet | Cottser: Node.module - Convert theme_ functions to Twig.
2014-02-13 16:54:28 +00:00
// Render trimmed teaser version of the post.
$node_teaser = node_view ( $node , 'teaser' );
2014-03-09 19:59:45 +00:00
$node_teaser [ '#attached' ][ 'library' ][] = 'node/drupal.node.preview' ;
Issue #1987406 by jenlampton, Petr Illek, forbesgraham, herom, jerdavis, Jon Pugh, sanguis, idflood, ezeedub, shanethehat, joelpittet | Cottser: Node.module - Convert theme_ functions to Twig.
2014-02-13 16:54:28 +00:00
$variables [ 'teaser' ] = $node_teaser ;
// Render full version of the post.
$node_full = node_view ( $node , 'full' );
$variables [ 'full' ] = $node_full ;
// Display a preview of the teaser only if the content of the teaser is
// different to the full post.
if ( $variables [ 'teaser' ] != $variables [ '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>' ));
Issue #1987406 by jenlampton, Petr Illek, forbesgraham, herom, jerdavis, Jon Pugh, sanguis, idflood, ezeedub, shanethehat, joelpittet | Cottser: Node.module - Convert theme_ functions to Twig.
2014-02-13 16:54:28 +00:00
$variables [ 'preview_teaser' ] = TRUE ;
2007-08-20 07:03:08 +00:00
}
else {
Issue #1987406 by jenlampton, Petr Illek, forbesgraham, herom, jerdavis, Jon Pugh, sanguis, idflood, ezeedub, shanethehat, joelpittet | Cottser: Node.module - Convert theme_ functions to Twig.
2014-02-13 16:54:28 +00:00
$variables [ 'preview_teaser' ] = FALSE ;
2007-08-20 07:03:08 +00:00
}
}