Hia, I'm quite new to theme function overrides, but have figured out the basics. However, I need to override a theme function within a different theme function. Have a look at this from the Spaces module:

function spaces_spaces_design_logo($filepath) {
  return theme('imagecache', 'spaces-logo', $filepath);
} 

which calls this function from the Imagacache module:

function theme_imagecache($presetname, $path, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE) {
  // Check is_null() so people can intentionally pass an empty array of
  // to override the defaults completely.
  if (is_null($attributes)) {
    $attributes = array('class' => 'imagecache imagecache-'. $presetname);
  }
  if ($getsize && ($image = image_get_info(imagecache_create_path($presetname, $path)))) {
    $attributes['width'] = $image['width'];
    $attributes['height'] = $image['height'];
  }

  $attributes = drupal_attributes($attributes);
  $imagecache_url = imagecache_create_url($presetname, $path);
  return '<img src="'. $imagecache_url .'" alt="'. check_plain($alt) .'" title="'. check_plain($title) .'" '. $attributes .' />';
}

What I ultimately want to do is change the output of the last line in theme_imagecache so it only outputs the URL to the image. This is straightforward to change directly with overriding theme_imagecache, but I need to change from this within the spaces_spaces_design_logo() function so it only affects the spaces logo, and here I need some help. With my limited php knowledge I have tried the following without any success:

function mytheme_spaces_design_logo($filepath) {
  function theme_imagecache($presetname, $path, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE) {
  // Check is_null() so people can intentionally pass an empty array of
  // to override the defaults completely.
  if (is_null($attributes)) {
    $attributes = array('class' => 'imagecache imagecache-'. $presetname);
  }
  if ($getsize && ($image = image_get_info(imagecache_create_path($presetname, $path)))) {
    $attributes['width'] = $image['width'];
    $attributes['height'] = $image['height'];
  }

  $attributes = drupal_attributes($attributes);
  $imagecache_url = imagecache_create_url($presetname, $path);
  return $imagecache_url;
 }
} 

this gives a white screen of death, so it's obviously not the correct way to do it..!

So, any help or pointers to how you change the output of one theme function from within a different theme function greatly appreciated! I'm sure it's really simple, but haven't been able to google my way to the answer :)

Comments

jacine’s picture

Hi,

You can't put functions inside of functions, so that's why your site is blowing up :(

If you look at the ginko theme's template.php you'll find hints and an example of the correct way to do what you are looking to do:

From ginko's template.php:

/**
 * Make logo markup overridable.
 */
function ginkgo_spaces_design_logo($filepath) {
  $url = imagecache_create_url('spaces-logo', $filepath);
  $space = spaces_get_space();
  $options = array(
    'attributes' => array(
      'class' => 'spaces-logo',
      'style' => 'background-image:url(\''. $url .'\')'
    ),
  );
  return l($space->title, '<front>', $options);
}

So basically, if all you want out of this function is the url to the image, you would do the following:

function youttheme_spaces_design_logo($filepath) {
  return imagecache_create_url('spaces-logo', $filepath);
}
vegardjo’s picture

Ah, now I see, thanks a bundle!

I didn't realize I had access to the imagecache_create_url() function from outside of the theme_imagecache() function, but that is indeed very useful to know.. :)

BTW: I wanted the URL to use it in CSS as my .header {background-image: ..}, and have now succeeded, thanks again!