Commit 7fe73532 authored by jcnventura's avatar jcnventura

Issue #1551406 by Shiraz Dindar: pass view_mode as argument to print_controller().

parent 9d21706e
......@@ -10,6 +10,8 @@
* @ingroup print
*/
define('PRINT_VIEW_MODE', 'print');
define('PRINT_LOGO_OPTIONS_DEFAULT', 1);
define('PRINT_LOGO_URL_DEFAULT', '');
define('PRINT_FOOTER_OPTIONS_DEFAULT', 1);
......@@ -114,7 +116,7 @@ function print_theme() {
* Implements hook_preprocess_HOOK().
*/
function print_preprocess_node(&$variables) {
if (($variables['elements']['#view_mode'] == 'print') && isset($variables['elements']['#print_format'])) {
if (($variables['elements']['#view_mode'] == PRINT_VIEW_MODE) && isset($variables['elements']['#print_format'])) {
$type = $variables['elements']['#node']->type;
$format = $variables['elements']['#print_format'];
$nid = $variables['elements']['#node']->nid;
......@@ -244,7 +246,7 @@ function print_node_delete($node) {
function print_entity_info_alter(&$info) {
// Add the 'Print' view mode for nodes.
$info['node']['view modes'] += array(
'print' => array(
PRINT_VIEW_MODE => array(
'label' => t('Print'),
'custom settings' => FALSE,
),
......@@ -252,7 +254,7 @@ function print_entity_info_alter(&$info) {
// Add the 'Print' view mode for field_collections
if (module_exists('field_collection')) {
$info['field_collection_item']['view modes'] += array(
'print' => array(
PRINT_VIEW_MODE => array(
'label' => t('Print'),
'custom settings' => FALSE,
),
......
......@@ -55,8 +55,8 @@ function print_controller_html() {
* format of the page being generated
* @param int $cid
* comment ID of the individual comment to be rendered
* @param bool $teaser
* if set to TRUE, outputs only the node's teaser
* @param string $view_mode
* (optional) view mode to be used when rendering the content
*
* @return object
* node-like object to be used in the print template
......@@ -66,7 +66,7 @@ function print_controller_html() {
* @see _print_generate_book()
* @see print_preprocess_print()
*/
function print_controller($path, $format, $cid = NULL, $teaser = FALSE) {
function print_controller($path, $format, $cid = NULL, $view_mode = PRINT_VIEW_MODE) {
if (empty($path)) {
// If no path was provided, let's try to generate a page for the referer
global $base_url;
......@@ -90,7 +90,7 @@ function print_controller($path, $format, $cid = NULL, $teaser = FALSE) {
$revision_view = preg_match('!^[\d]*/revisions/[\d]*/view$!', $path);
if (ctype_digit($parts[0]) && ((count($parts) == 1) || $revision_view)) {
$vid = $revision_view ? $parts[2] : NULL;
$node = _print_generate_node($path, $format, $vid, $cid, $teaser);
$node = _print_generate_node($path, $format, $vid, $cid, $view_mode);
}
else {
$ret = preg_match('!^book/export/html/(.*)!i', $path, $matches);
......@@ -561,13 +561,13 @@ function _print_url_list_enabled($node, $format) {
* (optional) revision ID of the node to use
* @param int $cid
* (optional) comment ID of the individual comment to be rendered
* @param bool $teaser
* (optional) if set to TRUE, outputs only the node's teaser
* @param string $view_mode
* (optional) view mode to be used when rendering the content
*
* @return object
* filled node-like object to be used in the print template
*/
function _print_generate_node($nid, $format, $vid = NULL, $cid = NULL, $teaser = FALSE) {
function _print_generate_node($nid, $format, $vid = NULL, $cid = NULL, $view_mode = PRINT_VIEW_MODE) {
global $_print_urls;
if (!isset($langcode)) {
......@@ -588,8 +588,6 @@ function _print_generate_node($nid, $format, $vid = NULL, $cid = NULL, $teaser =
}
drupal_set_title($node->title);
$view_mode = $teaser ? 'teaser' : 'print';
if ($cid === NULL) {
// Adapted (simplified) version of node_view
// Render the node content
......
......@@ -88,17 +88,19 @@ function print_epub_controller() {
* (optional) comment ID of the comment to render.
* @param string $epub_filename
* (optional) filename of the generated EPUB
* @param string $view_mode
* (optional) view mode to be used when rendering the content
*
* @return
* generated EPUB page, or NULL in case of error
*
* @see print_epub_controller()
*/
function print_epub_generate_path($path, $cid = NULL, $epub_filename = NULL) {
function print_epub_generate_path($path, $cid = NULL, $epub_filename = NULL, $view_mode = PRINT_VIEW_MODE) {
global $base_url;
$link = print_epub_print_link();
$node = print_controller($path, $link['format'], $cid);
$node = print_controller($path, $link['format'], $cid, $view_mode);
if ($node) {
$html = theme('print', array('node' => $node, 'expand_css' => TRUE, 'format' => $link['format']));
......
......@@ -298,7 +298,8 @@ function print_mail_form_submit($form, &$form_state) {
$sender_message = t('Message from sender') . ':<br /><br /><em>' . nl2br(check_plain($form_state['values']['txt_message'])) . '</em>';
$node = print_controller($form_state['values']['path'], $link['format'], $cid, $form_state['values']['chk_teaser']);
$view_mode = $form_state['values']['chk_teaser'] ? 'teaser' : PRINT_VIEW_MODE;
$node = print_controller($form_state['values']['path'], $link['format'], $cid, $view_mode);
// Spaces in img URLs must be replaced with %20
$pattern = '!<(img\s[^>]*?)>!is';
......
......@@ -88,17 +88,19 @@ function print_pdf_controller() {
* (optional) comment ID of the comment to render.
* @param string $pdf_filename
* (optional) filename of the generated PDF
* @param string $view_mode
* (optional) view mode to be used when rendering the content
*
* @return
* generated PDF page, or NULL in case of error
*
* @see print_pdf_controller()
*/
function print_pdf_generate_path($path, $cid = NULL, $pdf_filename = NULL) {
function print_pdf_generate_path($path, $cid = NULL, $pdf_filename = NULL, $view_mode = PRINT_VIEW_MODE) {
global $base_url;
$link = print_pdf_print_link();
$node = print_controller($path, $link['format'], $cid);
$node = print_controller($path, $link['format'], $cid, $view_mode);
if ($node) {
// Call the current tool's hook_pdf_tool_info(), to see if we need to expand CSS
$pdf_tool = explode('|', variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment