theme_image_button() in form.inc prepends base_path() to the image src, meaning that only local images can be rendered in an image_button.

D7 does it right: theme_image_button() calls file_create_url() which handles both internal and external URIs -- by checking whether :// exists in the URI with file_uri_scheme().

There is no file_uri_scheme() in D6. What's the best way to get external image support into a form's image_button in D6?
...Add the URI scheme checking code to theme_image_button()?
...Add file_uri_scheme() to D6?

Comments

jeffschuler’s picture

Status: Active » Closed (won't fix)

Or, (ahem)...

One could just override theme_image_button()
by adding THEMENAME_image_button() to template.php:

<?php
function THEMENAME_image_button($element) {
  // Make sure not to overwrite classes.
  if (isset($element['#attributes']['class'])) {
    $element['#attributes']['class'] = 'form-'. $element['#button_type'] .' '. $element['#attributes']['class'];
  }
  else {
    $element['#attributes']['class'] = 'form-'. $element['#button_type'];
  }
  
  $src_uri = $element['#src'];
  
  $data = explode('://', $src_uri, 2);
  $scheme = count($data) == 2 ? $data[0] : FALSE;
  
  if (!$scheme) {
    $src_uri = base_path() . '/' . $element['#src'];
  }

  return '<input type="image" name="'. $element['#name'] .'" '.
    (!empty($element['#value']) ? ('value="'. check_plain($element['#value']) .'" ') : '') .
    'id="'. $element['#id'] .'" '.
    drupal_attributes($element['#attributes']) .
    ' src="' . $src_uri . '" ' .
    (!empty($element['#title']) ? 'alt="'. check_plain($element['#title']) .'" title="'. check_plain($element['#title']) .'" ' : '' ) .
    "/>\n";
}
?>
beautifulmind’s picture

Thank you jeffschuler for sharing the code.

Regards.