Due piccole “drupallate”

Premessa: certo che scrivere di Drupal su un blog che gira su Wordpress non è proprio l’ideale :-P

Ma veniamo a noi: intanto, non mi capacito ancora di come possa essermi sfuggito questo, sito veramente utile e stranamente disperdente (della filosofia accentrante e/o concentrante riguardo le risorse su Drupal ha già accennato qui), anche se, a onor del vero, ci sono arrivato tramite Drupal.org.

E poi, sempre per rimanere in tema di dispersione delle fonti, mi premeva segnalare questo mio commento su Drupal.org: in pratica, rimaneggiando un paio di suggerimenti presi in giro per forum e handbook (ma soprattutto, facendo il tutto senza saper scrivere una sola riga di codice in PHP!), ho prodotto questo:

/*
* Change l() function to include "<span>"
*/

function l_span($text, $path, $attributes = array(), $query = NULL, $fragment = NULL, $absolute = FALSE, $html = FALSE) {
if ($path == $_GET['q']) {
if (isset($attributes['class'])) {
$attributes['class'] .= ' active';
}
else {
$attributes['class'] = 'active';
}
}

return '<a href="'. check_url(url($path, $query, $fragment, $absolute)) .'"'. drupal_attributes($attributes) .'><span>'. ($html ? $text : check_plain($text)) .'</span></a>';
}

/*
* Make theme for primary links with l_span() function
*/

function phptemplate_prilinks($links, $attributes = array('class' => 'links')) {
$output = '';

if (count($links) > 0) {
$output = '<ul'. drupal_attributes($attributes) .'>';

$num_links = count($links);
$i = 1;

foreach ($links as $key => $link) {
$class = '';

// Automatically add a class to each link and also to each LI
if (isset($link['attributes']) && isset($link['attributes']['class'])) {
$link['attributes']['class'] .= ' ' . $key;
$class = $key;
}
else {
$link['attributes']['class'] = $key;
$class = $key;
}

// Add first and last classes to the list of links to help out themers.
$extra_class = '';
if ($i == 1) {
$extra_class .= 'first ';
}
if ($i == $num_links) {
$extra_class .= 'last ';
}
$output .= '<li class="'. $extra_class . $class .'">';

// Is the title HTML?
$html = isset($link['html']) && $link['html'];

// Initialize fragment and query variables.
$link['query'] = isset($link['query']) ? $link['query'] : NULL;
$link['fragment'] = isset($link['fragment']) ? $link['fragment'] : NULL;

if (isset($link['href'])) {
$output .= l_span($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment'], FALSE, $html);
}

else if ($link['title']) {
//Some links are actually not links, but we wrap these in <span> for adding title and class attributes
if (!$html) {
$link['title'] = check_plain($link['title']);
}
$output .= '<span'. drupal_attributes($link['attributes']) .'>'. $link['title'] .'</span>';
}

$i++;
$output .= "</li>\n";
}

$output .= '</ul>';
}

return $output;
}

che fondamentalmente serve a inserire un bel <span> all’interno di un link in questo modo:

<a href="indirizzo"><span>Testo del link</span></a>

Ciò detto per i Primary Links, al fine di avere un output in HTML che permetta di usare gli ormai famosi tabs sliding doors proposti da A List Apart (qui tradotto in italiano).

Ovviamente, tutto il codice sopra riportato va inserito in un bel file phptemplate.php nella directory del vostro tema.

Con questo spero di aver fatto cosa gradita ai drupallici italiani che come me si sono sbattuti per avere i benedetti tabs sliding doors con l’hover di colore diverso dal link normale :-D

Nessun Commento

  1. Ancora nessun commento, perché non inizi tu? Usa il form qui sotto.

Scrivi un commento