Appunti, Drupal

Notes  

Come nascondere i Tabs inutilizzati

tags: Drupal  
drupal tags: search   tabs  

Capita di dover nascondere o eliminare alcuni Tabs di navigazione che Drupal o qualche suo modulo offrono di default.

Per farlo in modo pulito senza mettere mano al codice possiamo sfruttare phptemplate e inserire in seguente codice nel file template.php del nostro tema (o crearne uno appositamente in caso non sia già disponibile):


<?php

/**
* Override or insert PHPTemplate variables into the templates.
*/
function _phptemplate_variables($hook, $vars) {
if ($hook == 'page') {

Notes  

Drupal: how to translate single CCK fields values

tags: Drupal  
drupal tags: translations   CCK   Locale  

Out of the box the localization and translation functionalities of Drupal can translate only the titles of each field created with the Content Construction Kit (CCK). Unfortunately at the moment no translation module (Locale, Localizer, i18n) offers direct support for the translation of cck fields, so we have to fix this ourselves.

In order for a string to get translated it must be enveloped by the t() function in the PHP code. We have to do this manually. Currently, your 'Allowed values' list probably looks like:

Apples
Oranges

First you'd better chage it to::

Notes  

Drupal: hide Log Message textarea in node forms

tags: Drupal   php snippets  
drupal tags: user interaction   phptemplate  

If like me you are not a big fan of the Log Message functionality of Drupal (the one that adds a "Log Message" textarea at the bottom of each node form), then here is a small php snippet override to add to the template.php file of your theme to definitely hide the Message Log:

/**
* Override node form and remove "Log message" textarea
*/
function phptemplate_node_form($form) {
  $form['log']['#access'] = FALSE;
  return drupal_render($form);
}

Make a good use of it ;)

Notes  

Collapse contents in Drupal

tags: Drupal   javascript  
drupal tags: blocks   content  
To show and hide contents in Drupal we can use the javascript library in the core and obtain the same effect that we get by default in the collapsible fields of Drupal forms. All is needed is to invoke the script collapse.js in the body of the content (node or block) we are creating:
Notes  

Translate Drupal front page (i18n)

tags: Drupal   php snippets  
drupal tags: translations   i18n  
If you're using the i18n module to translate a website's contents, and you need also to have a specific homepage for each language, here are a couple of ways to get it:

if you use a custom PHPTemplate front page (page-front.tpl.php

you can call the node of the translation corresponding to the language actually in use:
Notes  

Fivestar module: auto refresh after vote

drupal tags: single modules   Fivestar   reload  

Fivestar is a little contributed Drupal module that allows you to cast a vote on any content type. I prefer it to other rating modules because it's simple and elegant, and it can be skinned to your likes easily as well.

Notes  

Drupal: show content only to anonymous / authenticated users

tags: Drupal   php snippets  
drupal tags: users   contents  

Is very easy to show some contents to anonymous AND some other to authenticated users in Drupal. You'll only need to adapt the following few lines of php to output your content:

<?php
global $user;
if (!
$user->uid) { ?>

    <div>anonymous content here</div>
<?php } else { ?>
    <div>authenticated content here</div>
<?php } ?>

Yep, that easy.

Notes  

How to add destination to URL in Drupal

tags: Drupal   php snippets  
drupal tags: navigation   user interaction  

Ever had the need to redirect your users to a certain page after they perform a particular task (ie: after they are invited to register to the site)?

Doing it is simple:

just translate the link in your PHPTemplate content-type file (es: node.tpl.php) from:
http://www.mywebsite.com/user/register

to:

Notes  

Make node $terms (links) point to contents from it's author only

tags: Drupal   php snippets  
drupal tags: categories   users  

Inglese: Come utilizzare i link dei termini ($terms) associati a ciascun nodo di Drupal per navigare altri contenuti dello stesso autore taggati con lo stesso termine?

Notes  

Show different content to anonymous and authenticated users

tags: Drupal   php snippets  
drupal tags: users   contents  

<?php
/**
* The following simple snippet
* displays different information to anonymous/logged in users within a page.
*
* This works with drupal 4.5 and drupal 4.6
*/
global $user;
if (
$user->uid) {
    return
"This message is only visible for logged-in users.";
}
if (!
$user->uid) {
    return
"This message is only visible for not-logged-in users.";
}
?>

Add to calendar

Archives

February 2012
SunMonTueWedThuFriSat
1234
567891011
12131415161718
19202122232425
26272829
PureDivs Drupal Themes Conversions
PureDivs Conversione Temi Drupal