Drupal 6.x

Change theme variables in your module

This is how you can affect variables before sent to theme templates based on the URL. In this case I had to remove an empty sidebar in RootCandy theme.

<?php
/**
 * Implementation of hook_preprocess_page().
 */
function support_filter_preprocess_page(&$vars) {
  if (
arg(0) == "domainuser" OR arg(0) == "support_filter") {
     unset(
$vars['admin_left']);
  }

}
?>

Don't forget to rebuild theme registry by use admin_menu modules Flush all caches > Theme Registry or drupal_rebuild_theme_registry();

How to split a text into chuncks containing a maximum number of characters and retain full sentences

This is how you can split a text into chuncks containing a maximum number of characters and retain full sentences.As an example, if you have a limit of 5000 characters, as in the case of Google Translate API, and would like to divide the text into chunks, but you do not want sentences or words to be divided in the middle.

Install Drupal modules programmatically

This is how you can install Drupal modules programmatically

<?php
function mymodule_install_features() {

   
$items = array();
   
drupal_install_modules(array( 'mymodule_cck', 'mymodule_views', 'mymodule_nodetypes'));
   
drupal_set_message("Installed features for Mymodule");
   
drupal_flush_all_caches();
    return
$items;
}
?>

And taxonomy

install_include(array('taxonomy'));
$props = array('module' => 'taxonomy', 'multiple' => 1);
install_taxonomy_add_vocabulary('Plants', array('article' => 'article'), $props);

$props = ar

Drupal delivery flow - moving stuff to live site

Drupal taxonomy term function


/**
* Get for l_keywords from vocabulary to
* dropbox in widget
*
*/
function _get_l_keywords() {

$vid = cdt_keywordlink_get_vocabulary();
$pole = array();
$items = array();
$terms = taxonomy_get_tree($vid);

if($result = db_query('SELECT * FROM {term_data} WHERE vid = %d', $vid)) {

while ($data = db_fetch_object($result)) {
$matches[$data->tid] = check_plain($data->name);
}
}

if (count($matches) > 0) {
return $matches;
}else{
drupal_set_message("There is no l_keywords registered in the cdt_keywordlink vocabu

How to reset a form on AHAH drupal_jason call

This is how you can reset a form on a Drupal AHAH call by sending a JavaScript with the drupal_json call.

 

<?php
   $domaintable
= _get_domain_table($_POST['uid']);

  
$domaintable .= '<script type="text/javascript">
                    var domainForm = document.getElementById("domainuser-add-domain-form");
                    domainForm.reset();
                    </script>'
;

   return
drupal_json($domaintable);
   exit();
?>

How to create a user specific RSS feed

  1. Get latest version of Views node feed, for now its just a dev version a bit hidden here http://drupal.org/node/271269/release, views_node_feed-6.x-1.x-dev
  2.  Install Views Node Feed at admin/build/modules
  3. If you have an WYSIWYG editor, exclude it from:
    admin/settings/views_node_feed/add.edit-wrapper
    admin/settings/views_node_feed/add.edit-node
    admin/settings/views_node_feed/edit*
  4. Go to admin/settings/views_node_feed and create a node

Add a datepicker programmatically with jquery_ui

This is some idea on how you can add a datepicker programmatically with the jquery_ui module. This code is not working as it is, its just some code I have cut out from my code. You have to match the form id in the jquery script as the drupal form creates. Look for edit-from, edit-to, edit-month in the script. I have here two alternative jquery scripts. And you find more scripts at the link to jqueryui.com below.

 

 

Pages