How to alter CCK form fields programmatically
This is how you can alter CCK form fields programmatically in your module. As you might noticed you can't find your CCK fields in the regular form_alter hook.
This is how you can alter CCK form fields programmatically in your module. As you might noticed you can't find your CCK fields in the regular form_alter hook.
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' => "
This is how you can render the node object for presentation. With the variable $node_out you get the ready to use HTML code for the node content. The $node object get extended with view elements for CCK fields and body is ready to use HTML.
<?php
$node = node_load($nid);
$node_out = node_view($node);
print $node_out;
?>
<pre>
<?php
print_r($node);
?>
</pre>
<?php
?>
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)),
);
}
?>
This is how you redirect after Save, Update and Delete by changing the action. Do not use #redirect in form because it wont work with Delete operation.
<?php
$spaces = spaces_get_space();
$spaces->group->purl;
?>
Drupal complete path with base, returns http://www.yoursite.com/node/[nid]
<?php
global $base_root;
$base_root . request_uri();
?>
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
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,
<?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']));
}
?>