Drupal

Override Field Value in Drupal Views Attachment using hook_views_pre_render()

Overriding views data can typically be accomplished using the commonly used hook_preprocess_views_view(&$vars) hook. However, I ran into a situation where I was unable to override field data using the preprocess hook. While building a view to show a list of products within certain categories, I added an attachment view which rendered the taxonomy name and description. The client wanted to taxonomy name on one page to be different than the actual taxonomy name.

Set Views Title Programatically in Drupal 7

<?php
function YOUR_MODULE_preprocess_views_view(&$vars) {
 
  // If it is the view you want to change
  if ($vars['view']->name == 'your_view') {
 
    // Override view's title, drupal_set_title() was not working
    $vars['view']->build_info['title'] = $my_title;
 
  }
}

Create a Numeric Pager for Views Slideshow in Drupal 7

  1. Add a new field to your view.
  2. In the search box type Global
  3. Choose Global: View result counter
  4. Click add and configure field
  5. Uncheck the Create a label checkbox
  6. Check Exclude from display
  7. Click Apply this display
  8. Go to the slideshow settings
  9. Enable the pager in the location of your choice
  10. Choose fields for the pager type
  11. Select the Global: View result counter as the field
  12. Click Apply this display

Drupal 7 Custom Views Layout - theme_preprocess_views_view_fields()

function NAME-OF-THEME_preprocess_views_view_fields(&$vars, $hook){
 
// machine name of view
if ($vars['view']->name == 'homepage_slideshow') {
 
    // add a wrapper before a certain field
    $vars['fields']['field_slide_image']->wrapper_prefix = '<div class="slideshow-content-wrapper-left">' .

Drupal CRON Setup and Scheduling - cron.php

From the command line, open the crontab using the default editor. You can change your default editor, just google the commands.

crontab -e

And then add the line:

30 23 * * * php /home/account/public_html/cron.php

This will run cron.php at 11:30 every day. For more configuration settings, see the drupal page or this good tutorial.

Configure LAMP Server for Drupal 7 and Migrate Development Site - No GUI, command line only

To start with, I created a tarball with bz2 compression of the dev site. Make sure to explicitly include .htaccess because the tar command, like the ls command does not include filenames with "." as the first character. Navigate to the root of your site and execute the following (-c create | -v verbose (lists files as it goes) | -j bz2 compression | -f file):

tar -cvjf nameofsite_date_of_copy.tar.bz2 * .htaccess

Also, you will need the mysqldump

Custom Drupal Views and Fields using hook_views_api() and hook_views_data()

Create a custom module to use a database table for a view.

Replace MODULENAME with the name of your module and TABLENAME with the name of your table.

Drupal Views Title from Argument - Use Views Argument as Page Title

<?php
    $view = views_get_current_view();
 
    $args = $view->args;
 
    drupal_set_title($args[0]);
 
 
    // if argument is taxonomy
    // $termObject = taxonomy_get_term($args[0]);
    // drupal_set_title($termObject->name);
?>

Show SKU in Cart Module - Ubercart

Create a folder in your modules directory named uc_show_sku and add these files.

Custom Product Template Drupal Ubercart: node-product.tpl.php

<!--
Modification of ubercart product template: this one should look very similar to the 'default look'.
It has only few selected fields and comes with Lightbox support.
-->
<?php
  drupal_add_js("misc/collapse.js");
?>
 
<?php // Grabs the firsts image path and sets $imagePath.
$imagePath = $node->field_image_cache['0']['filepath'];
?>
 
<!-- node and node inner -->
<div class="node <?php print $node_classes ?>" id="node-<?php print $node->nid; ?>">
 
        <?php if ($unpublished || $submitted): ?>
                <div class="node-top">
                        <?ph

Syndicate content