Before all, thanks for this very great and powerful module !

I'm looking for a solution to my need, which is to display a user social widget, only in the case he has configured his concerned social profile. I don't want the site-wide widget by default, nor a error box...
Let's take this example : I wish to add the "Facebook like box" for the author of a node in the full node display. If the user did not set any Facebook profile (in his "Social profiles" tab), I wish nothing to be produced.

I followed these steps :

  • Add a new widget set through admin/structure/widgets/sets/add
  • Add an element (widget) "Facebook like box"
  • In the widget form, I typed the token "[user:sm-facebook_url]" for the "Facebook page url" input, I think it's the way to only get the user widget and not the site one by default ; I suppose I can do this since I've seen that the socialmedia module added tokens that I suppose to correspond to the user inputs in his "Social profiles" tab [see note below]
  • After adding this element, check block in Visibility and Cache by node author, then Update set
  • Note that the preview says "There was an error fetching the like box for the specified page.", which is normal here because of the lack of a user context
  • In admin/structure/block, make the corresponding block visible somewhere
  • When you display something with a user context (content written by a user, or a user page), if the user has set a Facebook page, the block displays as expected (cool!) ; if not, the block displays "There was an error fetching the like box for the specified page." (normal but I would prefer the block not produced!). In this last case, the used token "[user:sm-facebook_url]" is probably null, but the widget seems to be systematically produced ; I think the concerned code is theme_widgets_set_view() in widgets.module; how to correct it in order not to generate any block content when the social parameter (here the facebook url) is not available? Can anyone help me for this?

[note] In admin/help/token we can see three very similar token families : [socialmedia:sm-facebook_url] (default value in the widget configuration form), [user:sm-facebook_url] and [site:sm-facebook_url]... Can you confirm that [socialmedia:sm-facebook_url] toggles between the user or the site range depending on the context (what I've noticed)? Is this usage suitable? Is there a documentation about the use of these tokens and the way to tune the cache settings accordingly?

Thanks for your help.

#1 widgets.module.patch1.22 KBpverrier
#1 fb-error-box.jpg21.38 KBpverrier


pverrier’s picture

new21.38 KB
new1.22 KB

I joined a screenshot of what happens when the user hasn't set a facebook account. It's this error box I'd like to hide...

I found this solution, widely using tokens : I unchecked the Block generation for the widget set, and I checked the Token generation : I will manually generate the block content, only if the user has set a facebook account ; to know this, I generate the [user:sm-facebook_url] token value and check if it's empty.
I created a custom block having PHP filtering, with this :

  $tok = token_replace('[user:sm-facebook_url]');
  if (!empty($tok) && $tok!='http://')  print token_replace('[widgets:ws-w_user_facebook_like_box]');
The token [widgets:ws-w_user_facebook_like_box] is the one generated by widgets ; it uses the [user:sm-facebook_url] parameter.

Nethertheless, I think the best solution would be not to generate the widget when the main parameter (facebook url here) is not valid. The following patch is a begin but is not sufficient because it only considers the case of the "facebook widget like box", with the parameter named 'facebook_page_url'. In order to generalize, probably the best way is to have naming rules (prefix) for the parameter names in order to identify which is the social identifier in the $data array (like 'facebook_page_url' or 'twitter_username', or any other social reference), by this way we could verify if its token-generated value is empty or not (for instance check any parameter prefixed with 'ref_')...

Note about the $tok=='http://' test : curiously for facebook_page_url I get a "http://" value for the [user:sm-facebook_url] token when the user did not enter a value for his facebook profile (I expected it was simply empty).

lsolesen’s picture

Status:Active» Needs review
drastik’s picture

This is still an issue. Doesn't fall back to site-wide properly if user values aren't present (a user's Social Profiles page has been submitted, but not all filled in).

That patch isn't in proper format and looks like it only deals w/ Facebook.

drastik’s picture

Title:How to avoid generation for user only widget if the concerned user has not set his social profile ?» Fall back to site-wide profile if user has not set his social profile
Version:7.x-1.0-beta8» 7.x-1.x-dev
Category:Feature request» Bug report
Issue summary:View changes
Status:Needs review» Active

Ways to replicate:

  1. Put block somewhere on the page.
  2. Submit site-wide profiles page so there are defaults to fall to.
  3. Submit the "Social Profiles" tab/page for a user, but don't fill all of them in (including some you are showing in the block).
  4. Go to a user's profile page.
  5. See[socialmedia:sm-twitter_username] as an example URL for a button (instead of falling back to site-wide).