Activity publisher templates are great, and you can insert HTML within the text field in order to change the output of the activity message. However, what should be done here is what Views does with registering .tpl files in order to be able to theme these messages. Then each message that is present upon a system will have a list of files that can be used to theme on the following levels:
- all messages for a particular module implementing activity (node, user, comment activities)
-- activity-node.tpl
- all messages for a particular module/operation combination (say theme all node-inserts whether it be the message the author sees or the public sees)
-- activity-node-insert.tpl
- each individual message (theme node-insert author differently than node-insert public)
-- activity-node-insert-author.tpl
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | activity_485436.patch | 3.58 KB | Scott Reynolds |
Comments
Comment #1
sirkitree commentedHowever, we do not want this system confused with the template system in general as it somewhat different.
These 'template' files will determine how the message is actually recorded to the database rather then how it is themed on output. If output needs themed, standard views theming should be used as all display goes through there. However there is still the need to be able to separate different elements _within_ the message, therefor we have the ability to enter html around the tokens.
These activity template files will have to be used INSTEAD of the token system - so either/or. This way when a template file is used, we can pass the objects into the activity template in order to format the message which will still be recorded into the database. Changing these files will not effect any OLD activity message that are already recorded, and thus is very different from the concept of the theme layer/current template where changing the tpl file changes any output.
Comment #2
Scott Reynolds commentedOk went ahead and gave this a shot. It was fun :-D, bit of a dive into theme(). You can create templates like this
Its not so either/or. In this patch you can choose not to use the $message variable.
We probably should add this as well but I want this patch out there for debate.
http://skitch.com/supermanscott/nr1ah/activity-theme
So this allows you to do
And that will use the activity-message--basic.tpl.php for all inserts of story or pages, given that you have the activity template setup for nodeapi insert only for those two types.
Comment #3
sirkitree commented*gasp!* ? .DS_Store in the patch - you using mac!? w00t! ;)
But this is awesome.
I think it still begs the question: is this an abuse of the template system? Maybe I'll throw the question out on the dev list...
Also, what is the reason for the double underscores? I know views tpls do this, but i was never sure on the reasoning behind it? Just uniqueness?
Also I see I had a note about this needing to replace the token system we have in place, but it seems like you were able to keep it. Can you elaborate on that a little please?
Comment #4
Scott Reynolds commentedThere was no rational other then, "Hey this doesn't have to be either or, a theme implementer can choose to use it or not. O and I don't have to remove that textareas from the interface!". But I think it makes sense too, as you could want to theme up messages differently depending on node types for instance. Seemed to create flexibility...
Right and to leverage developers existing experience for creating tpls. I don't think we need to describe the pattern here as it doesn't do us any good, i think. I have to try it without the 'pattern'.
This patch isn't complete really, its missing several things, like determining if that 'pattern' is needed. But wanted to get it out so we could dissect.
Comment #5
Scott Reynolds commentedFor improvement: http://drupal.org/node/223440 ? Maybe? I think that limits us to only tpl.php the current patch allows you to use theme functions as well. But nonetheless, important link
Comment #6
pribeh commentedHmmm. #5 poses a good question. I heavily use theme suggestions for my sites but have yet to try the patch in #2 and see how Scott's system.
Comment #7
Scott Reynolds commentedI think the technique in 5 is unwarranted.
It is not what Views does.
It is not what Flag does.
That technique in 5, would force the theming to be done in a tpl file. Whereas, the patch allows it to be a function or a tpl file. And it is similar to the technique of Flag and Views.
I believe 5 is a non-starter.
Comment #8
Scott Reynolds commentedChanging title to reflect my previous comment
Comment #9
pribeh commentedCool. Well I look forward to testing this patch and reporting back soon. Thanks for all your hard work Scott.
Comment #10
quicksketchSubscribing, this would be a very useful addition. We have a situation where we want to display Fivestar ratings as themed stars (we've written a VotingAPI implementation for activity already). However, we don't want to include the Fivestar themed stars in the stored message, since any changes to the theme layer would not be reflected in the stored message.
So our stored message would be something like "Admin gave Example a rating of 80" (where 80 == 4 of 5 stars). But then we could use the theme layer to replace "a rating of 80" with the themed stars provide by Fivestar through
theme('fivestar_static', $rating).I should also note that I'm not entirely sure that a .tpl.php file is necessary for this implementation. You can do the exact same thing for theme functions actually, so instead of tpl.php files, you would have a series of suggested theme functions which would follow this pattern:
An entire .tpl.php file just for
<?php print $message ?>seems excessive. Especially when considering that .tpl.php files are several times slower to render than theme functions (due to the preprocess functions). However that could be an advantage since it'd allow other modules to modify the $message variable too.Comment #11
quicksketchAh, I was getting all confused, I thought this was for theming messages on output not on record. I suppose we already have something for output, since it all runs through Views right? My use-case is solved through that.
All-in-all is theming stuff on input a good idea then? It seems like you'd want to avoid inserting a lot of HTML into the database that could never be changed (for example, I definitely wouldn't want to shove themed Fivestar widgets into the database). Though not storing messages would mean a completely different paradigm, where the objects (or object IDs) were stored in the database and then rendered into HTML on output. So maybe I'm just getting in over my head here. ;-)
* quicksketch steps out as if he'd never said anything
Comment #12
Scott Reynolds commentedwell i think sirkitree and myself had our doubts about this DX and I think this just confirms our doubts.
the goal was to provide powerful messages without having to do expensive left joins through node table and through cck table to get fields. We can do this with a relationship to CCK tables which is probably better overall.
Not sure it makes sense though to do it this way anymore. It was cool that it worked but thinking that this is a wont fix
Comment #13
pribeh commentedI agree with quicksketch in #11 ;)