The module automatically overrides a site-wide widget with the user-wide one, if the concerned user set his social profile url. This occurs when a user page is shown or a node full content page (the author's widget is displayed). That's great !
I'd like to extend this functionality to other cases. My need is to display a user's widget on a taxonomy term list (taxonomy/term/11 for instance) : in the term definition, I have a taxonomy reference field that gives the user attached to the term (the user in charge of the content section defined by the term). When a taxonomy term listing is displayed, I'd like to have the user-wide social widget displayed, instead of the site-wide one.
To do this, I suggest the following patch which calls a dedicated hook "hook_socialmedia_get_context_uid()". It allows other modules to set a user context in other cases ; I modified socialmedia_tokens() in socialmedia.tokens.inc.
Here's my module hook implementation as example :
function mymodule_socialmedia_get_context_uid() {
$arg = arg();
if (count($arg)==3 && $arg[0]=='taxonomy' && $arg[1]=='term') {
return _mymodule__get_field_value('field_authors','taxonomy_term','section',$arg[2],'_uid'); // returns the UID of the user in charge of the content section
}
return NULL;
}
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | hook_v2.patch | 3.37 KB | pverrier |
| socialmedia.tokens.inc_.patch | 721 bytes | pverrier |
Comments
Comment #1
TomDude48 commentedGood idea, thanks for the patch. I applied it and pushed it to the dev branch.
Comment #2
pverrier commentedCool ! Thanks.
Comment #3
pverrier commentedI was wondering how cache works, and if I've well understood I believe that the hook has also to be called in widgets_build_cache_cid() (file widgets.module), in the block "
elseif ($scope == 'author') {" in order to generate the good cache id $cid. By the way this code is very similar to the one in socialmedia_tokens() I've modified (file socialmedia.tokens.ink).It's annoying the hook has to be called from two distinct modules.
Can a dependency be set on widgets (cf. http://drupal.org/node/1415236) ? In this case it would be better to factorize this code in widgets and rename the hook 'widgets_get_context_uid'. I join the patch with these changes...
Comment #4
TomDude48 commentedI implemented something a long the lines of your suggestion. There is now a single function
widgets_get_context_author_uid()that is used for setting cache cids and social media's uid for profile loads.I throw a
drupal_alter('widgets_context_author_uid', $uid, $context);hook so you can implement your customizations. I think that will work for what you are trying to do.Let me know if this works for you. (you will need the latest pushes of both Social Media and Widgets)
Tom
Comment #5
pverrier commentedThanks, works fine !
Comment #6
TomDude48 commentedCool. When you get the site done send me a link. I would like to see what you got going on there.