Posted by naeluh on November 16, 2011 at 10:54pm
Hi I saw this post http://drupal.org/node/1276278#comment-5098978 on drupal.org in the issue queue for the module Redirect 403 to User Login and i was trying to accomplish a simliar thing. I am in pressflow 6.
I wanted to know how to add rel or class tags to a url in module? or Am I way off base in this ?
I have this snippet from the module -
$path = _r4032login_remove_language(request_uri());
// using drupal_goto() with destination set causes a recursive redirect loop
header('Location: '. url('user/login', array('query' => 'destination='. $path, 'absolute' => TRUE)), TRUE, 302);
exit;
}
elseif (!empty($redirect)) {
header('Location: '. url($redirect));
exit;
}
// checking arg() returns r4032login
elseif ($_REQUEST['q'] == 'user/register') {
print theme('page', theme('r4032login_user_register'));
exit;
}
else {
print theme('page', theme('r4032login_denied'));
exit;
}Am I supposed to add a class="colorbox-load" or rel="lightmodal" somewhere in here?
By the way had a great time at the downtown meetup last nite !
Let me know if I can help in any way!
thanks,
Nick

Comments
try l() instead of url()
Hi Nick,
What about trying the l() function instead?
"When creating links in modules, consider whether l() could be a better alternative than url()." (from url() api page)
http://api.drupal.org/api/drupal/includes--common.inc/function/l/6
The l() function -- for links -- allows for an attributes array as part of it's options, where you can provide the HTML attributes with your link tags.
From the example code provided, you'd do something like:
$options['attributes']['class'] = 'active';
Thanks
Thanks I am going to try it right now !
I will let you know how it goes thanks !
Also this is the full function:Does that make any difference ?
Can I still use that l() function even though it has this function already set up?
thanks again for all your help!
Nick
function r4032login_redirect() {global $user;
$redirect = variable_get('r4032login_redirect_authenticated_users_to', '');
if (user_is_anonymous()) {
// Only display the message if there is one.
$message = variable_get('r4032login_display_denied_message', 'Access denied. You must login to view this page.');
if (!empty($message)) {
drupal_set_message(t($message), 'error');
}
// Check for path prefix and strip it out if its found.
$path = _r4032login_remove_language(request_uri());
// using drupal_goto() with destination set causes a recursive redirect loop
header('Location: '. url('user/login', array('query' => 'destination='. $path, 'absolute' => TRUE)), TRUE, 302);
exit;
}
elseif (!empty($redirect)) {
header('Location: '. url($redirect));
exit;
}
// checking arg() returns r4032login
elseif ($_REQUEST['q'] == 'user/register') {
print theme('page', theme('r4032login_user_register'));
exit;
}
else {
print theme('page', theme('r4032login_denied'));
exit;
}
}
I ended up with this and it is creating the wrong url?
I converted this line to
header('Location: '. url('user/login', array('query' => 'destination='. $path, 'absolute' => TRUE)), TRUE, 302);exit;
}
header('Location: '. l('','user/login', array('query' => 'destination='. $path, 'absolute' => TRUE ,'attributes' => array('class' => 'colorbox-load'))), TRUE, 302);exit;
}
It returns the url
http://50.57.55.106/features/117/%3Ca%20href=%22http://50.57.55.106/user/login?destination=/features/117/assimilation-fog%22%20class=%22colorbox-load%22%3E%3C/a%3EWhat I want is this url to return thru a colorbox
http://50.57.55.106/user/login?destination=/features/117/matt-kempAny one have any thoughts as to what I could do?
thanks so much!!
Nick
Can I use l() without adding a href wrapper?
Its seems based off of this comment that l() function will not work because it produces the a href wrapper when it is used. As stated here -
http://api.drupal.org/api/drupal/includes--common.inc/function/l/6#comme...
Is there a way to add class to a url() function?
thanks !
Nick
What was the question again?
I am a little confused as to what you want to accomplish.
Why not just use javascript and add the colorbox function to click event. Then you can use the class it already has.
This is assuming that you want to have a colorbox popup when you a user clicks something.
If not then...
All the url function does is generate an internal or external url (read http://api.drupal.org/api/drupal/includes--common.inc/function/url/6 for the spec) because all it does is generate a url a wrapping tag would have to be used to give that url a class. This is because a url is not a valid html tag, a url is just text, one can only attach classes to html tags. Thus I have no idea what you are trying to do.