Restored guide
Replacing Submit Button Image Using CSS
The original entry lived on this blog between 2008 and 2011. The explanation here is rewritten from public Drupal APIs so the same path can be read again. The note is titled “Replacing Submit Button Image Using CSS” and is written for Drupal 6.x unless a line below says otherwise.
What you are solving
Image work in this era means ImageCache presets, ImageField, and a derivative that is generated on demand. Generate heavy presets from Drush or a queue so a single anonymous page view does not exhaust the PHP memory limit. The moving parts in the historical title are: replacing, submit, button, image, using, css.
APIs and modules in play
- a custom module with the narrowest hook that can see the data
- clearing cache and the theme registry after the change
A practical approach
- Step 1. Name the outcome in one sentence: Replacing Submit Button Image Using CSS.
- Step 2. Reproduce it on a development copy with the same modules enabled.
- Step 3. Keep the change in a custom module or in the theme, and leave contributed code untouched.
- Step 4. Define the preset (scale, crop, or scale-and-crop) before you write code that assumes a derivative path.
- Step 5. Flush only the presets you changed, and generate them from CLI when the source images are large.
Example
The sample is illustrative. Rename the function, swap in your machine names, and run it on a development copy.
// Replacing Submit Button Image Using CSS
function notes_replacing_submit_button_image_using_css_preset_url($filepath, $preset = 'thumbnail') {
$preset = check_plain($preset);
return file_create_url('imagecache/' . $preset . '/' . $filepath);
}Check before you deploy
- Confirm the change on a database copy, then again with the theme registry and page cache cleared.
- Watch the PHP error log and the watchdog table for the first real request.
- If the change alters markup, recheck the path with a keyboard and without JavaScript.
Restored guide. The original post was published by Eric London on this domain. This text is a new explanation of that subject, not a reproduction of the archived wording.