Drupal 6.x

How to add colorpicker to a form textfield

This is how you can add colorpicker to a form textfield for instance in your theme settings file.


drupal_add_css('misc/farbtastic/farbtastic.css');
drupal_add_js('misc/farbtastic/farbtastic.js');

$form['color'] = array(
'#type' => 'textfield',
'#title' => t('Color pickmeup'),
'#default_value' => '#123456',
'#description' => '

',
);

$form['colorpicker_example'] = array(
'#type' => 'item',
'#description' => "

Just some open atrium code...

Just some open atrium code...

<?php
$context
= context_get('spaces', 'dashboard') ? context_get('context', context_get('spaces', 'dashboard')) : FALSE;
    if (
spaces_dashboard_access('admin') && $context) {
      return array(
       
'subject' => t('Dashboard'),
       
'content' => drupal_get_form('spaces_dashboard_editor', array($context)),
      );
    }
?>

Drupal user access role function

This is a little function that can be used like user_access but for checking if the user is in some role.

/**
* Check if user has role
*
* @param unknown_type $role
* @return unknown
*/
function _user_has_role($role) {
global $user;

if (is_string($role)) {
$role = array($role);
}

foreach ($role as $key => $role_name) {
if (in_array($role_name, $user->roles)) {
return TRUE;
}
}

return FALSE;

}

//implementation of has one of the roles
if (_user_has_role(array('sales', 'management', 'admin'))) {
//some actio

How to sort views summary on term weight programmatically

This is how you can sort your view on taxonomy term weight programmatically instead of using the default Summary, sorted ascending/descending

/*
* Hook views_pre_execute
*
*/
function mymodule_views_pre_execute(&$view) {
if ($view->name == 'opportunity_summary' && $view->current_display == 'block_1') {
$search = array('ORDER BY term_data_name ASC');
$replace = array('ORDER BY term_data.weight ASC');
$view->build_info['query'] = str_replace($search, $replace, $view->build_info['query']);
$view->build_info['count_query'] = str_replace($search, $replace,

Get term from modules vocabulary

<?php
function atrium_opportunity_get_term($value="New", $voc = "features_opportunity_state"){

 
$vid = db_result(db_query("SELECT vid FROM {vocabulary} WHERE module = '%s';", $voc));

 
$term = db_fetch_array(db_query('SELECT tid FROM {term_data} WHERE name LIKE "%s" AND vid = %d', $value, $vid));

  return array(
$vid => array($term['tid'] => $term['tid']));
}
?>

Pages