Following on from http://drupal.org/node/221608, I'm looking at getting templates into these modules.

First impressions of getting the theme layer into image.module:
There's too many nested theming calls at the moment.
We have:
- theme_image_teaser/body
-- calls image_display
--- calls theme_image_display

Nesting theming calls seems weird to me. Especially if we switch to using a tpl.php template.

I can change it, but it involves taking a hatchet to a lot of code -- probably replacing all those different theming calls with a single theme_image_display and a preprocess function that sorts out all the data.
What do you think, drewish?

CommentFileSizeAuthor
#3 image theming layer.patch6.18 KBjoachim
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

drewish’s picture

i'd say take a hatchet to it. a lot of that code is still in the whole 4.6 frame of mind. lets pretend we're doing it right the first time... i would really like to end up with .tpl files to make it easier for themers.

joachim’s picture

Hatchet it is then!

I'm thinking there should be one template file for images. That way all images can easily be themed in one place.
At the same time, this should allow to distinguish between images in full nodes / teasers / block / view / gallery / attached to other nodes as full node or teaser, etc.

I'm going to have a stab at doing it the way I've described here: http://groups.drupal.org/node/11780

joachim’s picture

FileSize
6.18 KB

Here is a patch for image.module.
It adds a template file for displaying both teasers and body images.

Here's an explanation of the changes to theming functions:

The existing flow is like this:
- theme_image_{teaser/body} -- optionally wraps a link around the call to...
-- image_display -- gets image info, build CSS classes, gets sizes
--- theme_image_display -- bare wrapper
---- theme_image -- core function -- returns an Only local images are allowed. tag

New flow:
- theme_image_body -- calls a preprocessor function...
-- template_preprocess_image_body -- build up data in preprocessor:
* get image info
* build CSS classes
* get sizes
* create IMG tag from core theme_image
--- hand all this to the template file image.tpl.php

theme_image_teaser works the same way:
- theme_image_teaser -- calls a preprocessor function...
-- template_preprocess_image_teaser -- build up data in preprocessor
* call the main preprocessor, template_preprocess_image_body
* wrap the IMG in a link element, while storing the original IMG snippet
in case a themer wants to have access to it.

image_display() remains, even though it's not used by this module's theming code any more -- some submodules call it and so does views support in this module.
The next job will be to clean that up.

I've also moved a couple of functions in the code so all the theming-type stuff is together, and in the order of flow.

drewish’s picture

Status: Active » Needs work

for template_preprocess_image_body() i'd check isset($variables['size']) before calling empty($variables['node']->images[$variables['size']])

the rest looks pretty reasonable. seem like it's still a work in progress.

joachim’s picture

Right. That check I copied from image_display(). Consider it Frankencode, as TBH I'm not entirely sure what case it's checking for.

I'm starting a new job tomorrow and I really don't know how much time I'll have for working on this, if any.
Can I hand this on to you and the coding sprint you have planned (unless that's already happened... in which case, image code spring in Szeged? I'd really like to revive that plan of walkah's that's on there somewhere.)

sun’s picture

Status: Needs work » Closed (won't fix)

I'm opposed to this, considering the performance decrease that comes with templates. Feel free to re-open this issue.