Tag Archive for drupal

Views API module declaration

function {module_name}_views_api() {
return array('api' => 2.0);
}

source

Image Cache Preset manuell im Template verwenden

theme('imagecache', Imagecache-Preset, filepath,title,alt);

source

Drupal FiveStar custom widget

<?php
$votes = fivestar_get_votes($content_type, $content_id, $tag);
$node_type = $node->type;

$values = array(
'user' => empty($votes['user']['value']) ? 0 : $votes['user']['value'],
'average' => (int)$value,
'count' => empty($votes['count']['value']) ? 0 : $votes['count']['value'],
);

$settings = array(
'stars' => variable_get('fivestar_stars_'. $node_type, 5),
'allow_clear' => variable_get('fivestar_unvote_'. $node_type, FALSE),
// If the user has setup this content type to use smart stars, display
// the smart version instead of just the average.
'style' => variable_get('fivestar_style_'. $node_type, 'average') != 'smart' ? 'average' : 'smart',
'text' => $summary ? variable_get('fivestar_text_'. $node_type, 'dual') : 'none',
'content_type' => 'node',
'content_id' => $node->nid,
'tag' => $tag,
'autosubmit' => TRUE,
'title' => FALSE,
'feedback_enable' => $summary ? variable_get('fivestar_feedback_'. $node_type, 1) : FALSE,
'labels_enable' => $summary ? variable_get('fivestar_labels_enable_'. $node_type, 1) : FALSE,
'labels' => $summary ? variable_get('fivestar_labels_'. $node_type, array()) : array(),
);

print drupal_get_form('fivestar_custom_widget', $values, $settings);
?>

source

hook_form_alter for views exposed filter form

/**
* Implementation of hook_form_FORM_ID_alter() for 'views exposed form'
* Change the first option label '<All>' to 'Filter by Identifier Name' for exposed filters
* The filter identifier needs set up with underscores for multiple word filter names
* e.g. 'document_type' becomes 'Document Type'
*/

function mymodule_form_views_exposed_form_alter (&$form, $form_state) {
foreach($form as $key => &$value) {
if(isset($value['#options']['All'])) {
$label = ucwords(strtolower(str_replace('_', ' ', $key)));
$value['#options']['All'] = t('Filter by !label', array('!label' => $label));
}
}
}

source

Use drush sql dump to dump the database to the file system.

drush sql dump > /path/to/BACKUPS/site_name-$(date +%Y-%m-%d-%H.%M.%S).sql

source

Use drush sql dump to dump the database to the file system.

drush sql dump > /path/to/BACKUPS/site_name-$(date +%Y-%m-%d-%H.%M.%S).sql

source

Use drush to dump a space separated list of enabled modules to a text file.

drush statusmodules --pipe | cat > mods_enabled.txt

source

Drupal hook_block 6.x

<?php

function hook_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {

case 'list':
$blocks[0]['info'] = t('Block 1');
$blocks[1]['info'] = t('Block 2');
return $blocks;

case 'configure':
if ($delta == 0 && user_access('administer module')) {
$form['module_block_1'] = array();
}
if ($delta == 1 && user_access('administer module')) {
$form['module_block_2'] = array();
}
return $form;

case 'save':
if ($delta == 0) {
variable_set('module_block_setting_1', $edit['module_block_1']);
}
if ($delta == 1) {
variable_set('module_block_setting_2', $edit['module_block_2']);
}
break;

case 'view':
if ($delta == 0) {
$block['subject'] = t('Block 1 title');
$block['content'] = t('Block 1 content');
}
if ($delta == 1) {
$block['subject'] = t('Block 2 title');
$block['content'] = t('Block 2 content');
}

return $block;
}
}

source

drupal json

//output json
drupal_json(array(
'mrates' => $current_m_rates,
'frates' => $current_f_rates,
)
);

source

Set drupal cronjob via command line

# To edit a crontab through the command line, type the following (may need root priv):

crontab -e

# Add ONE of the following lines:

45 * * * *  /usr/bin/lynx -source <a href="http://example.com/cron.php" >http://example.com/cron.php</a>
45 * * * * /usr/bin/wget -O - -q -t 1 <a href="http://www.example.com/cron.php" >http://www.example.com/cron.php</a>
45 * * * * curl --silent --compressed <a href="http://example.com/cron.php" >http://example.com/cron.php</a>

# This would have a lynx, wget, or curl visit your cron page 45 minutes after every hour.

source