From 275d800b9500dfaa77bb15270528299036ef8058 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Thu, 28 Feb 2013 20:54:42 +0100 Subject: [PATCH] Added the ability to preview a print page for a given object. --- islandora.module | 31 +++++++++++++++++++++++++++++++ theme/theme.inc | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/islandora.module b/islandora.module index d5287286..189d01fc 100644 --- a/islandora.module +++ b/islandora.module @@ -228,6 +228,15 @@ function islandora_menu() { 'access arguments' => array(FEDORA_PURGE, 2, 4), 'load arguments' => array(2), ); + $items['islandora/object/%islandora_object/print'] = array( + 'title' => 'Print Object', + 'page callback' => 'islandora_print_object', + 'page arguments' => array(2), + 'type' => MENU_CALLBACK, + 'access callback' => 'islandora_object_access_callback', + 'access arguments' => array(FEDORA_VIEW_OBJECTS, 2), + 'load arguments' => array(2), + ); $items['islandora/ingest'] = array( 'title' => 'Add an Object', 'page callback' => 'islandora_ingest_callback', @@ -271,6 +280,11 @@ function islandora_theme() { 'file' => 'includes/solution_packs.inc', 'render element' => 'form', ), + // Print object view. + 'islandora_object_print' => array( + 'file' => 'theme/theme.inc', + 'variables' => array('object' => NULL, 'content' => array()), + ), ); } @@ -928,3 +942,20 @@ function islandora_entity_property_info() { return $info; } + +/** + * Renders the print page for the given object. + * + * Modules can either implement preprocess functions to append content onto the + * 'content' variable, or override the display by providing a theme suggestion. + * + * @param FedoraObject $object + * The object. + * + * @return array + * A renderable array. + */ +function islandora_print_object(FedoraObject $object) { + drupal_set_title($object->label); + return theme('islandora_object_print', array('object' => $object)); +} diff --git a/theme/theme.inc b/theme/theme.inc index 1622d810..a37cda74 100644 --- a/theme/theme.inc +++ b/theme/theme.inc @@ -123,3 +123,41 @@ function islandora_preprocess_islandora_default(&$variables) { $variables['islandora_thumbnail_url'] = $base_url . '/islandora/object/' . $islandora_object->id . '/datastream/TN/view'; } } + +/** + * Implements hook_preprocess_theme(). + */ +function islandora_preprocess_islandora_object_print(array &$variables) { + // Apply the print CSS in non print context. + $only_print_media = function($o) { + return $o['media'] == 'print'; + }; + $css = array_filter(drupal_add_css(), $only_print_media); + foreach ($css as $data => $options) { + $options['media'] = 'all'; + drupal_add_css($data, $options); + } + // Allow modules to define their own theme suggestions for the given object. + // Suggestions are defined as islandora_object_print__CMODEL__PID. For + // example for the image object islandora:1234. + // islandora_object_print__islandora_imagecmodel + // islandora_object_print__islandora_imagecmodel__islandora_1234 + // would be valid theme suggestions. This step up does not support objects + // with multiple content models in which each content model provides a theme + // suggestion. + $object = $variables['object']; + $pid = strtolower(preg_replace('/[^a-zA-Z0-9_]/', '_', $object->id)); + $models = array_diff($object->models, array('fedora-system:FedoraObject-3.0')); + foreach ($models as $model) { + $model = strtolower(preg_replace('/[^a-zA-Z0-9_]/', '_', $model)); + $suggestions = theme_get_suggestions(array($model, $pid), 'islandora_object_print'); + $variables['theme_hook_suggestions'] = array_merge($variables['theme_hook_suggestions'], $suggestions); + } +} + +/** + * Implements theme_hook(). + */ +function theme_islandora_object_print(array &$variables) { + return drupal_render($variables['content']); +}