implement token hooks for blog information (helps integration with Pathauto and Auto Node titles and...)
orbface9 - May 5, 2008 - 20:52
| Project: | Blog Information |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
Is it possible to get the Blog Name from the Blog Information module to display in the url?
e.g. /blogs/[blog-information-name]

#1
Yes, but this would need to be done in the Blog Information module itself.
To the Blog Information maintainer or whomever writes this code - let me know if you need any help understanding what to do for this.
#2
thanks
#3
Will look at this in a while as I want this myself, but please don't expect any major improvement on this module before the D7 version. That's what I will be planing ahead for, but will backport if easy enough. Of course I will be open for patches any day as long as they don't carry major side effects.
#4
I implemented the token hooks and they seem to work, at least for me.
I've attached the revamped .module file as a .txt.
The only changes made are at the bottom of the file.
Like i said, it works for me, i didn't get into too much detail though, so maybe it could be fixed up for someone else's needs.
#5
#6
Ok thanks, I will check out the D5 branch and look at it. But before I put this in officially, if I do it, I want to see how this transfer to D6 and D7
#7
Ok it looked simple and easy to implement so comitted and 2.5RC2 released, and this will soon go into 6.x-1.x-dev as well
#8
@yettyn
I think it should work for D6 also, but i'll look into that further.
as for D7, there is not a -dev release of the tokens module available, so we can't test anything yet.
#9
@orbface9
Yes I am testing it in D6 right now, just wonder is there any special reason (I don't see) you include 'description' and 'format' in the db call
$results = db_query("SELECT title, description, format FROM {bloginfo} WHERE uid = %d", $user->uid);?
As for D7 yes it has to wait.
#10
Committed to the Drupal-6--1 branch and will soon show up in the dev release. The packager only run once every 12 hour for dev so have some patience ;-)
#11
There wasn't any reason to select the description and format, i just copied and pasted the sql query from a different part of the module. Here's the updated code.
<?phpfunction bloginfo_token_values($type, $object = NULL, $options = array()) {
if ($type == 'user') {
$user = $object;
$blogtitle = db_result(db_query("SELECT title FROM {bloginfo} WHERE uid = %d", $user->uid));
$tokens['blog-title'] = t($blogtitle);
}
else if ($type == 'node') {
$node = $object;
$blogtitle = db_result(db_query("SELECT title FROM {bloginfo} WHERE uid = %d", $node->uid));
$tokens['blog-title'] = t($blogtitle);
}
return $tokens;
}
function bloginfo_token_list($type = 'all') {
if ($type == 'user' || $type == 'all') {
$tokens['user']['blog-title'] = 'Blog Title from bloginfo module.';
}
if ($type == 'node' || $type == 'all') {
$tokens['node']['blog-title'] = 'Blog Title from bloginfo module.';
}
return $tokens;
}
?>
#12
@yettyn
I got to thinking. Either the bloginfo.info file needs to show the token module as a dependency, or we should add some filtering to the above code.
<?phpif (module_exists(token)) {
function bloginfo_token_values($type, $object = NULL, $options = array()) {
if ($type == 'user') {
$user = $object;
$blogtitle = db_result(db_query("SELECT title FROM {bloginfo} WHERE uid = %d", $user->uid));
$tokens['blog-title'] = t($blogtitle);
}
else if ($type == 'node') {
$node = $object;
$blogtitle = db_result(db_query("SELECT title FROM {bloginfo} WHERE uid = %d", $node->uid));
$tokens['blog-title'] = t($blogtitle);
}
return $tokens;
}
function bloginfo_token_list($type = 'all') {
if ($type == 'user' || $type == 'all') {
$tokens['user']['blog-title'] = 'Blog Title from bloginfo module.';
}
if ($type == 'node' || $type == 'all') {
$tokens['node']['blog-title'] = 'Blog Title from bloginfo module.';
}
return $tokens;
}
}
?>
This code is tested and working in D5 and D6, but adding the dependency would probably be easier and more logical.
#13
Sorry been ill for a few days...
good point, I am not sure we are having a dependency situation here though. That would mean the token module would provide a functionality essential for bloginfo to function and I don't think it's the case, not yet at least. I could go for the above code in testing for a while to make sure it doesn't impose any problems and then we will see for D7 if we make token a dependency or not.
Bottom line here again is that I don't want to plaw in a bunch of new functionality in D5 & D6 that people start to rely on but may cause problem in the upgrade path to D7. Behind this is a discussion going on if blog module should be in core or not and although it currently lean at it staying I have a feeling last word isn't said yet and there might be fundamental changes. So until D7 gone into freeze I want o play cautious about what to add.
Another thing, not specificly related, when an issue has been set to fixed and you feel a need it's somehow not or want to continue the discussion, please either reopen the issue or open a new one (possibly with a refer to the related issue). In most cases it's better to open a new issue, unless something really is wrong with the fix. This way the issue system comes to its most effective use and will make things easier and clearer for all of us.
#14
#15
Looks like this was committed - http://drupal.org/cvs?commit=148705 thanks!