I am creating a directory and added some fields for harvesting Social Media info - mainly Twitter and Facebook on a CCK content type called 'Directory Listing'. Most of the entities in the directory are organizations, companies, etc.

I had to harvest the entire Facebook page link, because their pages seem to follow some kind of archaic naming structure.

For Twitter, I wanted to harvest just the Twitter username because I would like to use it elsewhere as a token when making automated tweets by adding '@[token]' reference to the node title and url. So I collect the user name in a CCK field that is excluded from singular display and instead post the link to their Twitter Account embedded in a standardized link.

In CCK the field is a text field (widget type 'Text field') named 'field_twitter_username'. This is hidden from display, but is used as the base for the computed field called 'field_twitter_page_computed' which computes as follows:

//$node->field_twitter_username is the name of the CCK field that will be use to make the link
if ($node->field_twitter_username[0]['value']){
     /*variablized this to make it more flexible in terms of changing the base path in the future if needed.  I noticed 'Old Twitter' links were '/username' and 'New' (ca.12/2010) Twitter links are '/#!/username' */
     $twitter_addy="http://www.twitter.com/";
     //render the link while embedding the node title in the link's display text
     $node_field[0]['value'] = "<a href=\"".$twitter_addy.$node->field_twitter_username[0]['value']."\"      target=\"_twitter\">$node->title on Twitter</a>";
}

I then display 'field_twitter_page_computed' inline with it's label 'Twitter Page:'. The field is rendered in 'Raw text' style only in the full node.

Comments

Nisha_31’s picture

how to get value from url and pass it in computed field???...because get function is not workin!!
please help to solve my problem

sticky2010’s picture

This only provides a text with a link to the twitter page? Why not just have a text field in the Directory Listing Content Type where you can enter the url for each Directory Listing content?

Then you can pull respective url based on node id as the argument.

chowdah’s picture

Just updating the computed code for Drupal 7 because the language/format is slightly different:

$twit=$entity->field_twitter_username[LANGUAGE_NONE][0]['value'];
if ($twit){
$twitter_addy="http://www.twitter.com/";
$entity_field[0]['value'] = "<a href=\"".$twitter_addy.$twit."\" target=\"_twitter\">$entity->title on Twitter</a>";
}