Home

Stefano Mallozzi Professional web developmentStefano Mallozzi Professional web development

Condividi contenuti
  • About me
  • Bookmark
  • Tips and tricks
  • Tutorials
  • Contact me
  • Feed aggregator
Home

Languages

  • Italiano
  • English

Contact me

Links

Tag cloud

connection drupal i18n ics images internet lan network node images photo php seo
More tags

Photo galleries

  • Pictures of Gaeta

Fix missing loading of Javascript and CSS in hook_form_alter() when node form is not validated

Sun, 20/03/2011 - 02:02 — stefano

If you call functions drupal_add_js() or drupal_add_css() in a hook_form_alter() of a custom module, it may happen that if the form is not validated it won't load Javascrpt and CSS.
You can fix this problem by adding the #after_build to your form, and then moving drupal_add_js() and drupal_add_css() in the associated function. This way the hook_form_alter() will contains form elements only, and the #after_build will load Javascript and CSS.

Tags:
  • Drupal
  • drupal
  • form
  • validation
»
  • Italiano

mb_strlen() error when using date_popup element

Wed, 08/12/2010 - 18:09 — stefano

The date_popup module included in the date package allows you to create a calendar widget to add dates. You just need to set the date_popup type to a textbox element, for example:

  $form['start_date'] = array(
    '#type' => 'date_popup',
    '#title' => 'Start date',
    '#default_value' => $values['start_date'],
    '#date_format' => 'm/d/Y',
    '#size' => 13,
  );


A click in the textbox will show up a calendar widget to choose the date.
Be careful: DO NOT ADD the #maxlength property to the element, otherwise you will get an error like this:

warning: mb_strlen() expects parameter 1 to be string, array given in D:\localhost\drupal\includes\unicode.inc on line 410.

The error occurs because the date_popup module transforms the date value in an array, so the max length check performed by form validation execues the drupal_strlen function on an array and not a string.

Tags:
  • Drupal
  • date_popup
  • drupal
  • errors
  • modules
»
  • Italiano

Node images: manage images and photogalleries in Drupal

Sat, 24/01/2009 - 03:12 — stefano

The Node images project is a Drupal module to create photogalleries. It allows users to assign images to content and view those images in a gallery. Users may upload images inline in the content creation page, and then manage them in a specific page, to edit the current images or upload new ones.
Here are the main features of this module:

  • Advanced management of uploaded images (upload new images, choose the ones to list, change the visualization order).
  • Inline upload from the content creation page.
  • Ajax photogallery, showing thumbnail of uploaded images, and the current images in a Polaroid format.
  • Advanced upload settings (image size, max number of images per content, md5 file names, selection of content types to which associate images).
  • Fine grained permissions (add images to any content type or only specific ones, edit/delete all images or only own iamges).
  • Internationalization support for images description, through the i18strings module (included in the Internationalization package): image descriptions are available as translatable strings in the translate interface.

Photogallery demo: Pictures of Gaeta

Tags:
  • Drupal
  • development
  • drupal
  • gallery
  • i18n
  • images
  • node images
  • photo
  • php
  • translation
»
  • Italiano

How to add multilingual support to a Drupal 6 site

Wed, 31/12/2008 - 01:07 — stefano
  1. Install languages
    • Go to Site configuration ⇒ Languages and install the languages you need for your site.
    • Open the Configure tab and select Path prefix only.
  2. Enable modules
    • In the Modules page enable the following core modules: Locale, Content Translation.
    • Install the Internationalization module (i18n) and enable all the multilanguage modules except Poll aggregate and Profile translation.
    • In the Permissions page assign the right permissions added by the previous modules.
  3. Configure multilanguage
    • Go to Site configuration ⇒ Languages and edit each language (except the deefault one) setting an appropriate path prefix (usually the language code, i.e. "it" for Italian)..
    • Go to Site configuration ⇒ Languages ⇒ Multilingual system and select Current language and language neutral.
    • Edit the Drupal settings.php file, and enter the $conf['i18n_variables'] array with all the variables you want to translate, for example:

      $conf['i18n_variables'] = array(
      // Site configuration
      'site_slogan',
      'site_mission',
      'anonymous',
      // User configuration
      'user_registration_help',
      'usermail_welcome_subject',
      'user_mail_welcome_body',
      'user_mail_approval_subject',
      'user_mail_approval_body',
      'user_mail_pass_subject',
      'user_mail_pass_body',
      // Primary and secondary links
      'menu__primary_links_source',
      'menu__secondary_links_source',
      // Theme settings. This is an 'all or nothing' for each theme
      // This is for 'garland' theme, for other theme it would be 'theme_[themename]_settings'
      'theme_garland_settings',
      );

      Those variables will be translatable by changing the current language in your site.
  4. Built-in interface translation
    • Open the Blocks administration page and enable the Language switcher block. You'll see links to the active languages, and you'll be able to change the current language on your site.
  5. Blocks translation
    Create one block for each language, enter the translated content and select the appropriate languange in the Language field.
  6. Content translation
    • Open the Content types page, edit the content types you want to translate, and in the Workflow settings choose Enabled, translation included. You'll be able to write content in the default language, then you open the Translate page and write content in the other languages.
  7. Menu translation
    • Open the Menus page, add or edit a menu item, and select thet appropriate language in the Language field.
    • If you want to show in your page only the menus in the current language, for example the Primary links in italian when you select Italian, you need to edit the template.php file and add this snippet to the function phptemplate_preprocess_page():

      global $language;
      if (!empty($vars['primary_links'])) {
      foreach ((array)$vars['primary_links'] as $id => $link) {
      if ($link['langcode'] && strcmp($link['langcode'], $language->language) != 0) unset($vars['primary_links'][$id]);
      }
      }
  8. Taxonomy translation
    • Add or edit a vocabulary, in the Multilingual options select Set language to vocabulary...." and set the appropriate language. The terms added to each vocabulary will be shown only for the current language.
  9. Refresh translated strings
    • To get the new menu items and terms translated, go to Site building -> Translate interface, open the Refresh tab, check all the text groups and click Refresh strings.
Tags:
  • Tutorials
  • drupal
  • i18n
  • languages
  • multilanguage
  • translation
»
  • Italiano
Syndicate content

© Stefano Mallozzi
P.IVA 02155580596
Valid XHTML 1.0 Strict Valid CSS Valid RSS
Powered by Drupal Powered by Apache Powered by MySQL Powered by PHP