Доброго времени суток!
Подскажите пожалуйста, как можно сделать так, чтобы созданный через admin/build/menu пункт меню переставал отображался, после того, как пользователь авторизуется? Пункт ссылается на внешнюю ссылку.
И обратное: как после авторизации отобразить пункт меню, ссылающийся на внешнюю ссылку?
Куда копать-то?
Комментарии
можно переопределить функцию theme_links (она темизирует линки).
Вписываем в нее три строки кода:
if(substr_count($link['href'], "http://") && !$user->uid) unset($link);
$output .= $link ? '<li class="'. $class .'">' : '';
в итоге должно получится следующее:
$output = '';
global $user;
if (count($links) > 0) {
$output = '<ul'. drupal_attributes($attributes) .'>';
$num_links = count($links);
$i = 1;
foreach ($links as $key => $link) {
$class = $key;
if (substr_count($link['href'], "http://") && !$user->uid) {
unset($link);
}
if ($i == 1) {
$class .= ' first';
}
if ($i == $num_links) {
$class .= ' last';
}
if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))) {
$class .= ' active';
}
$output .= $link ? '<li class="'. $class .'">' : '';
if (isset($link['href'])) {
// Pass in $link as $options, they share the same keys.
$output .= l($link['title'], $link['href'], $link);
}
else if (!empty($link['title'])) {
// Some links are actually not links, but we wrap these in <span> for adding title and class attributes
if (empty($link['html'])) {
$link['title'] = check_plain($link['title']);
}
$span_attributes = '';
if (isset($link['attributes'])) {
$span_attributes = drupal_attributes($link['attributes']);
}
$output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
}
$i++;
$output .= "</li>\n";
}
$output .= '</ul>';
}
return $output;
}
Можно изящнее: Menu access