I have a paginated report with links that I want to be unpaginated and without links if it's being printed as a PDF. I thought I could do a simple boolean check for whether or not arg(0) was printpdf but that won't work because _print_generate_path() does a menu_set_active() which tricks Drupal into thinking I'm on the page that's being printed. I struggled with this for 20 minutes and finally resorted to checking $_SERVER['REQUEST_URI'] since that was the only place I could find the "true" path.

It'd be lovely if there was some extra context that was passed in so that I could easily switch on that.

Comments

jcnventura’s picture

Status: Active » Fixed

Check for $node->build_mode == 'print'.

João

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

ludo.r’s picture

Version: 6.x-1.x-dev » 7.x-1.0-beta1
Category: feature » support
Status: Closed (fixed) » Active

Hi,

I'm currently working in template_preprocess_page(), and I have to find out if the node is being printed.

There is no more $node->build_mode (or at least I don't see it in template_preprocess_page()).

Using arg() or $_GET['q'] always return 'node/123' instead of 'print /123'.

Does one have a solution on this issue?

Thanks!

jcnventura’s picture

Status: Active » Fixed

Don't open closed issues please..

The build mode is gone in 7.x, but Drupal now supports something called the view_mode. Unfortunately it's only defined at node level, so I'm not sure if you'll get it in template_preprocess_page().

ludo.r’s picture

Sorry, for re-opening.

You're right about preprocess_page() and preprocess_node().
But I've found a way to determine if the node is being printed :

function mytheme_preprocess_page(&$variables) {
  if (!empty($variables['node']) && isset($variables['print'])) {
    //Node is being printed, do something...
  }
}

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.