I am trying to do some customization of the IMCE interface, but it looks like hook_preprocess_page does not run in IMCE pages such as mysite.com/imce

You can verify this by adding die() at the beginning of any hook_preprocess_page call, and load the imce page.

I see there are some IMCE template files, but I'd like to add a CSS reference to the head, among other things, and would rather not hard code that reference in IMCE's page template.

Comments

ufku’s picture

IMCE page is created by theme('imce_page'), so the hook to be invoked is hook_preprocess_imce_page()

arnoldbird’s picture

theme('imce_page') provides the contents of the page, but not the whole page (in the usual Drupal sense).

Looks like the reason hook_preprocess_page does not run is because of the call to exit() in imce(). Instead of returning a renderable array in the usual Drupal 7 way, this page callback prints the page contents and then exits:

print imce_page($GLOBALS['user'], $scheme, $jsop);
exit();
arnoldbird’s picture

Looks like it's possible to create a page in a custom module that uses imce_content() to output the IMCE browser in the page content. Something like this...

function mymodule_page_imce() {
  
  require_once(drupal_get_path('module', 'imce') . '/inc/imce.page.inc');

  if (isset($_GET['app'])) {
    drupal_add_js(drupal_get_path('module', 'imce') . '/js/imce_set_app.js', array('weight' => 1000));
  }
  
  $jsop = isset($_GET['jsop']) ? $_GET['jsop'] : NULL;
  global $user;
  $output = imce_content($user, null, $jsop);
  
  return $output;

}

Initially it seems to work.

arnoldbird’s picture

The approach in #3 works, to some extent, but looks like it will have to be further customized for different situations. For example, when IMCE is used in an image field. Going back to the original issue, I'm not sure what we gain by printing the IMCE output and exiting, rather than returning the output (and thus handing things off to Drupal's presentation layer in the usual way). It's possible there is something I'm overlooking, but the non-standard approach to rendering the page doesn't have any advantages that I can see and makes theming much more complicated, for those who need to theme the IMCE browser.
Nevermind the above. I think the reason IMCE is not working in an image field is due to a bug in another module. It's not related to the print & exit in IMCE.

thalles’s picture

Issue summary: View changes

I think this was solved!

thalles’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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