Modifying a cck text field to yield a link

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
cithukyaw's picture

Hi Drupalers,

How to modify a cck text field to yield a link ?
I have a cck text fields with validation handler valid_url(), but it renders a plain text, not a link.

I think you will have a question - why not use cck link module ?
The reason is
1) cck link not validate "http://", it accepts internal path.
2) In my custom theme, it disappeared in node creation form, but it works on other default themes.

Thus, I changed my mind to use a text field with validation handler.
Unfortunately, it doesn't render a link in node content.

Any idea ?

Comments

The link module should work

caschbre's picture

The link module should work for internal and external URLs. I've used it in the past for both and haven't had an issue with it.

The l() function (http://api.drupal.org/api/drupal/includes--common.inc/function/l/6) should render a link for you if you want to go another route.

Variable $content before rendering

cithukyaw's picture

Yes, the link module works for both internal and external URLs, but what I mean is that I want it to accept external URLs only and I want it to have "http://" validation.
But, the main problem is that the link entry was completely disappeared in my custom theme.

I know the l() function renders a link as every drupaler knows that.

My temporary solution is that renders each elements in the template node-event.tpl.php, not using the variable $content.
Here is my code.

  <div class="content">
    <?php
    
print $field_start_date_rendered;
  print
$field_end_date_rendered;
    print
$field_location_rendered;
    print
str_replace($field_link[0]['value'], l($field_link[0]['value'], $field_link[0]['value']), $field_link_rendered); // this line prints the link
 
print $node->content['body']['#value'];
   
?>

  </div>

The main question is " Where can I wrap the text value with the l() function before going into the variable $content ?? ".

With Regards,
Sithu

Hmm... that's interesting

caschbre's picture

Hmm... that's interesting that the link module was disappearing in your theme. Have you used the Devel module before? That can help you trace through the variables for the page/object and find out how to access it and what the value is. That could help debug why it's not showing.

I'm not sure what you mean by wrap the text value before going into the variable.