Theming of content boxes - code is repeated inside each layout plugin and not abstract enough

electricmonk - January 7, 2009 - 11:36
Project:MySite
Version:5.x-3.3
Component:- Layout plugin
Category:task
Priority:normal
Assigned:Unassigned
Status:needs work
Description

Currently, the same piece of code used to theme the different boxes is repeated inside each layout plugin. In addition, if one wishes to change the appearance of all boxes, one has to override the layout theme function(s).

I've attached a patch which delegates the responsibility of theming the boxes themselves to a separate function. This makes for better software engineering and prevents the excess theme overriding mentioned above.

AttachmentSize
mysite.patch10.9 KB

#1

agentrickard - January 7, 2009 - 15:11
Category:bug report» task

That's a really good patch.

#2

electricmonk - January 12, 2009 - 15:10

It seems to work OK for me, but I'm only using the 'columns' layout. I hope that there weren't any small differences between the way boxes are rendered in the different layout plugins.

#3

agentrickard - January 12, 2009 - 15:16

I don't believe so. I think it was all just copy/paste.

The only reason for keeping the code separate is if people want to make changes to one layout but not another.

#4

electricmonk - January 12, 2009 - 15:57

Ok, so my patch is definitely a good idea - they can still do that by overriding the box theming function in their template file or elsewhere.

As a general rule, I strongly encourage using multiple layers of abstraction in order to allow users to override stuff without having to duplicate whole pages worth of functionality.

#5

agentrickard - January 12, 2009 - 16:46
Status:needs review» needs work

And if users want to re-theme one layout but not the others? We should probably pass a $layout parameter to the theme.

Understand that I agree with you, this is just a very early module that I wrote. I was surprised and pleased to get it to work at all.

#6

electricmonk - January 12, 2009 - 19:19

In this case, I would use a mediator theming function, which would look something like this: (I'm at home now, so I don't have the code in front of me)

<?php
function theme_mysite_box($args...) {
  
$func = theme_get_function('mysite_box_' . $layout);
   if (
$func) {
     
$func($args...)
   }
   else {
    
// default behavior, or a call to a default function
  
}
}
?>

What do you say?

#7

agentrickard - January 12, 2009 - 20:55

Works for me.

#8

electricmonk - January 20, 2009 - 13:12

Hmmm... so, are you waiting for me to make those changes, or are you going to implement them yourself sometime in the future?

#9

agentrickard - January 20, 2009 - 15:07

Waiting for a patch. This module is not in active development, and this is not critical.

#10

electricmonk - January 26, 2009 - 11:36

What I mean is - are you waiting for a patch submission by myself?

#11

agentrickard - January 26, 2009 - 15:54

Yes.

 
 

Drupal is a registered trademark of Dries Buytaert.