switch ($delta) {
case 'print-links':
$nid = preg_replace('!^node/!', '', $_GET['q']);
- if (is_numeric($nid)) {
+ if (ctype_digit($nid)) {
$node = node_load($nid);
}
else {
function print_node_view($node, $view_mode) {
$print_html_link_pos = variable_get('print_html_link_pos', array(PRINT_HTML_LINK_POS_DEFAULT => PRINT_HTML_LINK_POS_DEFAULT));
$print_html_link_use_alias = variable_get('print_html_link_use_alias', PRINT_HTML_LINK_USE_ALIAS_DEFAULT);
- $allowed_type = print_link_allowed(array('type' => 'node', 'node' => $node, 'teaser' => ($view_mode == 'teaser')));
+ $allowed_type = print_link_allowed(array('type' => 'node', 'node' => $node, 'view_mode' => $view_mode));
if (($allowed_type === PRINT_ALLOW_NORMAL_LINK) && !isset($node->book) && !empty($print_html_link_pos['link'])) {
drupal_add_css(drupal_get_path('module', 'print') . '/css/printlinks.css');
$links = array();
}
/**
- * Implements hook_field_build_modes().
+ * Implements hook_entity_info_alter().
*/
-function print_field_build_modes() {
- return array(
+function print_entity_info_alter(&$info) {
+ // Add the 'Print' view mode for nodes.
+ $info['node']['view modes'] += array(
'print' => array(
- 'title' => t('Print'),
- 'build modes' => array(
- 'print' => array(
- 'title' => t('Print'),
- 'views style' => TRUE,
- ),
- ),
+ 'label' => t('Print'),
+ 'custom settings' => FALSE,
),
);
}
function _print_get_title($path) {
$path = drupal_get_normal_path($path);
$nid = preg_replace('!^node/!', '', $path);
- if (is_numeric($nid)) {
+ if (ctype_digit($nid)) {
$res = db_query("SELECT title FROM {node} WHERE nid = :nid", array(':nid' => $nid))
->fetchField();
}
* PRINT_ALLOW_BOOK_LINK if a link is allowed in a book node
*/
function print_link_allowed($args) {
- if ((!empty($args['teaser']) && !variable_get('print_html_link_teaser', PRINT_HTML_LINK_TEASER_DEFAULT))
- || !user_access('access print')) {
+ $view_mode = isset($args['view_mode']) ? $args['view_mode'] : '';
+ if ((($view_mode == 'teaser') && !variable_get('print_html_link_teaser', PRINT_HTML_LINK_TEASER_DEFAULT))
+ || !in_array($view_mode, array('full', 'teaser')) || !user_access('access print')) {
// If the teaser link is disabled or the user is not allowed
return FALSE;
}
if (!empty($args['path'])) {
$nid = preg_replace('!^node/!', '', drupal_get_normal_path($args['path']));
- if (is_numeric($nid)) {
+ if (ctype_digit($nid)) {
$args['node'] = node_load($nid);
}
}