This code goes in template.php and replaces the text on the default search box:
function themename_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'search_block_form') {
$form['actions']['submit']['#value'] = t('Search');
}
}
Archive for the ‘ Drupal ’ Category
Fixing Drupal’s Clearfix CSS
Posted byDrupal’s default clearfix CSS leaves a gap at the bottom of the page, this removes this:
.clearfix:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
font-size: 0;
}
.clearfix { display: inline-block; }
/* \*/
* html .clearfix { height: 1%; }
.clearfix { display: block; }
/* */
Drupal 7 – Starting point for creating a file object programatically
Posted byIf you need to create a file object through the Drupal api then use the following code:
filename = basename('{CURRENT PATH}');
$file->filepath = '{CURRENT PATH}';
$file->filemime = file_get_mimetype($file->filename);
$file->filesize = filesize('{CURRENT PATH}');
$file->uid = $user->uid;
$file->status = FILE_STATUS_TEMPORARY;
$file->timestamp = time();
$file->list = 1;
$file = file_save($file);
$file = file_move($file, 'public://');
$file->status = FILE_STATUS_PERMANENT;
$file = file_save($file);
Drupal 7 – Starting point for programmatically creating a node
Posted byIf you need to create a node within your module then use the following code:
title = '{NODE TITLE}';
$node->type = '{NODE TYPE}';
node_object_prepare($node);
$node->language = LANGUAGE_NONE;
$node->uid = $user->uid;
$node->status = 1;
$node->promote = 0;
$node->comment = 0;
$node = node_submit($node);
node_save($node);
Define a Drupal 7 Block in a module
Posted byThe following code is used if you want to define a new block within a Drupal module. Replace hook_ with your modules name.
t('Block Description'),
);
return $blocks;
}
function hook_block_view($delta = '') {
$block = array();
switch ($delta) {
case 'block-name':
$block['content'] = hook_custom_function();
break;
}
return $block;
}
function hook_custom_function(){
$content = "Block Content";
return $content;
}
Drupal 7 – Hide breadcrumb when there is only one link
Posted byIf you need to hide breadcrumb links when there is only the Home link add this code to your template.php file – change hook_ with your themes name.
function hook_breadcrumb($variables) {
if (count($variables['breadcrumb']) == 1) {
return false;
}
}
Drupal 7 Skip to First Search Result if Only One
Posted byIf you want to alter the default Drupal 7 search so that it skips to the URL of the first result if there is only one then add the following code to your template.php
Change <template> with your template name.
function <template>_preprocess_search_results(&$variables) {
$resultcount =0;
foreach ($variables['results'] as $result) {
$resultcount += 1;
}
if($resultcount == 1){
drupal_goto($variables['results'][0]['link']);
}
}
Alter the node add form in Drupal 7
Posted byIf you want to change the Save button text to Submit in Drupal 7 add the following to your template.php file.
Simply replace YOURTHEME with the name of your theme and CONTENTTYPE to the machine name of your content type.
function YOURTHEME_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'CONTENTTYPE_node_form') {
$form['actions']['submit']['#value'] = t('Submit');
}
}
Printing CCK Fields in Drupal 7
Posted byIn node.tpl.php
<?php print render($content[‘field_EXAMPLE’]); ?>
<?php print render($content[‘body’]); ?>
In page.tpl.php
<?php print $node->field_EXAMPLE[‘und’][0][‘value’]; ?>
Notice: Undefined variable: site_name_and_slogan in include()
Posted byDrupal 7x
If you have copied the Garland theme and renamed the directory and garland.info file you need to change all references of garland in the template.php file to your new theme name.