Please help me to debug this module...

chris33 - April 28, 2008 - 08:51
Project:Video
Version:5.x-1.x-dev
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed
Description

I have installed a video module, and one of my co-programmers create a hack for this. The playtime is now not showing and some other important field of the video module. Please help me. Thanks.

This his code...

<?php
// $Id$

/**
* @file
* Customisations of Ubercart for Neb.
*
*/

define("cTaxonomyNameVideo", "Video");
define("cTaxonomyNameCatalog", "Catalog");


/******************************************************************************
* Drupal Hooks                                                               *
******************************************************************************/

/**
* Display help and module information
* @param section which section of the site we're displaying help
* @return help text for section
*/
function neb_ubercart_help($section = ''){
  // Do things here later. Figure out what you need to say for each section.
  switch($section){
    case 'admin/settings/module#description':
      $output = t('Customisations of Ubercart for Neb.');
      break;
  }
  return $output;
}

/**
* Valid permissions for this module
* @return array An array of valid permissions for the module
*/
function neb_ubercart_perm() {
  return array('artist product create');
}

/**
* Perform alterations before a form is rendered.
*/
function neb_ubercart_form_alter($form_id, &$form) {
  if ($form_id == 'video_node_form') {
    $logger =& neb_core_setupLogger();
    $logger->debug(__FUNCTION__ . ':' . __LINE__ . '(' . $form_id . ') - op = ' . $_POST['op']);
    if (user_access('artist product create')) {
      if ($_POST['op'] != 'Submit') {
        // we want artists to enter their cost
        $form['base']['prices']['cost']['#required'] = TRUE;
       
        // content fields to be removed
        unset($form['uc_repeater_export']);
        unset($form['path']);
        // hack: make attachments available, while video is not working
        // unset($form['attachments']);
        $form['attachments']['#title'] = 'Video';
        $form['attachments']['#collapsed'] = FALSE;
       
        unset($form['field_op_video']);
       
        // remove the category taxonomy as we will set it to
        foreach ($form['taxonomy'] as $key => $value) {
          if (is_array($value) && isset ($value['#title'])
              && strcmp($value['#title'], 'Catalog') == 0) {
            unset($form['taxonomy'][$key]);
            break;
          }
        }

        // product fields to be removed from display
        unset($form['base']['model']);
        unset($form['base']['prices']['list_price']);
        unset($form['base']['prices']['cost']);
        //unset($form['base']['prices']['sell_price']);
        unset($form['base']['shippable']);
        unset($form['base']['weight']);
        unset($form['base']['dimensions']);
        unset($form['base']['pkg_qty']);
        unset($form['base']['default_qty']);
        unset($form['base']['ordering']);


       
      }
      else {


        $logger->debug(__FUNCTION__ . ':' . __LINE__ . '(' . $form_id . ') - Submit');
        // remove the category taxonomy as we will set it to
        foreach ($form['taxonomy'] as $key => $value) {
          if (is_array($value) && isset ($value['#title'])
              && strcmp($value['#title'], 'Catalog') == 0) {
            $form['taxonomy'][$key]['#required'] = FALSE;
            break;
          }
        }

        // product fields to be removed from display
        unset($form['base']['model']);
        unset($form['base']['prices']['list_price']);
        unset($form['base']['prices']['cost']);
        //unset($form['base']['prices']['sell_price']);
        unset($form['base']['shippable']);
        unset($form['base']['weight']);
        unset($form['base']['dimensions']);
        unset($form['base']['pkg_qty']);
        unset($form['base']['default_qty']);
        unset($form['base']['ordering']);

       
        $form['base']['model']['#required'] = FALSE;
        $form['base']['prices']['list_price']['#required'] = FALSE;
        $form['base']['prices']['cost']['#required'] = FALSE;
        //$form['base']['prices']['sell_price']['#required'] = FALSE;
        $form['base']['shippable']['#required'] = FALSE;
        $form['base']['weight']['#required'] = FALSE;
        $form['base']['dimensions']['#required'] = FALSE;
        $form['base']['pkg_qty']['#required'] = FALSE;
        $form['base']['default_qty']['#required'] = FALSE;
        $form['base']['ordering']['#required'] = FALSE;
       
        // add a hook for our our custom validate function and ensure
        // it is first in the list
        $form['#validate']['neb_ubercart_form_validate'] = array();
        $form['#validate'] = array_reverse($form['#validate']);
        neb_core_logArray($logger, __FUNCTION__ . ':' . __LINE__, array_keys($form['#validate']), null, ', ');
        neb_core_logArray($logger, __FUNCTION__ . ':' . __LINE__, array_keys($form['#submit']), null, ', ');
      }



    }
  }
}

/**
* Add back in the values that we removed
*/
function neb_ubercart_form_validate($form_id, $form_values, $form) {
  $logger =& neb_core_setupLogger();
  $logger->debug(__FUNCTION__ . ':' . __LINE__ . '(' . $form_id . ')');
  if ($form_id == 'video_node_form') {
    if (user_access('artist product create')) {
      $logger->debug(__FUNCTION__ . ':' . __LINE__ . ' - change values ' .  print_r($form_values, true));

      // $logger->debug(__FUNCTION__ . ':' . __LINE__ . print_r($form['base']['prices']['sell_price'], TRUE));
      form_set_value($form['base']['model'], empty($form_values['model']) ? 'na' : $form_values['model']);
      form_set_value($form['base']['shippable'], empty($form_values['shippable']) ? FALSE : $form_values['shippable']);
      form_set_value($form['base']['pkg_qty'], empty($form_values['pkg_qty']) ? 1 : $form_values['pkg_qty']);
      form_set_value($form['base']['default_qty'], empty($form_values['default_qty']) ? 1 : $form_values['default_qty']);
      form_set_value($form['base']['ordering'], empty($form_values['ordering']) ? 0 : $form_values['ordering']);
      form_set_value($form['base']['prices']['cost'], 0.5 * $form_values['sell_price']);
      // Add a catalog taxonomy
     
      //$catalogTree = taxonomy_get_tree($catalogTid);
      $catalogKey = -1;
      $videoKey = -1;
      //$logger->debug(__FUNCTION__ . ':' . __LINE__ . ' - video = ' .  print_r($form['taxonomy'], true));
      foreach ($form['taxonomy'] as $key => $value) {
        if (is_array($value) && isset($value['#title'])) {
          //$logger->debug(__FUNCTION__ . ':' . __LINE__ . ' - title = ' . $value['#title']);
          switch ($value['#title']) {
            case 'Catalog' :
              $catalogKey = $key;
              break;
            case 'Video' :
              $videoKey = $key;
          }
        }
      }
      $logger->debug(__FUNCTION__ . ':' . __LINE__ . ' - catalogKey = ' . $catalogKey . ', videoKey = ' .  $videoKey);
      $logger->debug(__FUNCTION__ . ':' . __LINE__ . ' - video = ' .  print_r($form_values['taxonomy'][$videoKey], true));
      $logger->debug(__FUNCTION__ . ':' . __LINE__ . ' - video = ' .  print_r($form['taxonomy'][$videoKey]['#options'], true));

  if(is_array($form_values['taxonomy'][$videoKey]))
  {
      foreach ($form_values['taxonomy'][$videoKey] as $videoValueKey) {
         $videoName = neb_core_optionFindTaxonomyName($videoValueKey, $form['taxonomy'][$videoKey]['#options']);
        $catalogValueKey = neb_core_optionFindTaxonomyKey($videoName, $form['taxonomy'][$catalogKey]['#options']);
        $logger->debug(__FUNCTION__ . ':' . __LINE__ . ' - videoValueKey = ' . $videoValueKey);
        $logger->debug(__FUNCTION__ . ':' . __LINE__ . ' - video = ' .  $videoName . ', catalog = ' . $catalogValueKey);
        form_set_value($form['taxonomy'][$catalogKey], $catalogValueKey);
      }
  }
      $logger->debug(__FUNCTION__ . ':' . __LINE__ . print_r($form_values, true));
    }
  }
}

#1

chris33 - April 28, 2008 - 09:18
Status:patch (code needs review)» won't fix

#2

chris33 - April 28, 2008 - 09:19
Status:won't fix» closed
 
 

Drupal is a registered trademark of Dries Buytaert.