daily pastebin goal
44%
SHARE
TWEET

Untitled

benjamin_mcf Nov 11th, 2011 441 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function nodeform_form_alter(&$form, &$form_state, $form_id) {
  2.     if ($form_id == 'article_node_form') {
  3.  
  4.      
  5.       $form['#prefix'] = '<div style="background:#AAFF55;">';
  6.       $form['#suffix'] = '</div>';
  7.       $form['actions']['submit']['#value'] = t('Hammering');
  8.       $form['title']['#default_value'] = t('Dance');
  9.       $form['title']['#required'] = FALSE;
  10.      
  11.      
  12.      
  13.      
  14.      
  15.       $squery = db_select('taxonomy_term_data', 't');
  16.       $squery
  17.             ->fields('t', array('vid', 'name', 'tid', 'weight'))
  18.             ->condition('t.vid', 2, '=')
  19.             ->orderBy('t.weight', 'ASC');
  20.       $sresult = $squery->execute();
  21.       $soptions = array();
  22.       foreach ($sresult as $srow) {
  23.             $soptions[$srow->tid] = $srow->name;
  24.       };
  25.      
  26.       $gquery = db_select('taxonomy_term_data', 't');
  27.       $gquery
  28.             ->fields('t', array('vid', 'name', 'tid', 'weight'))
  29.             ->condition('t.vid', 3, '=')
  30.             ->orderBy('t.weight', 'ASC');
  31.       $gresult = $gquery->execute();
  32.       $goptions = array();
  33.       foreach ($gresult as $grow) {
  34.             $goptions[$grow->tid] = $grow->name;
  35.       };
  36.      
  37.       $subjids = array();  
  38.       if (!empty($form_state['values']['subject'])) {
  39.         $subjids = array_filter($form_state['values']['subject']);
  40.       }
  41.       $gradids = array();
  42.       if (!empty($form_state['values']['grade'])) {
  43.         $gradids = array_filter($form_state['values']['grade']);
  44.       }
  45.  
  46.       $topquery = db_select('taxonomy_term_data', 't');
  47.       $topquery->join('field_data_field_topic_subject', 's', 't.tid = s.entity_id');
  48.       $topquery->join(' field_data_field_topic_grade', 'g', 't.tid = g.entity_id');
  49.       $topquery->fields('t', array('vid', 'name', 'tid'));
  50.       $topquery->fields('s', array('field_topic_subject_tid'));
  51.       $topquery->fields('g', array('field_topic_grade_tid'));
  52.       $db_or = db_or();
  53.       foreach ($subjids as $subjid) {
  54.           $db_or->condition('s.field_topic_subject_tid', $subjid, '=');    
  55.           $topquery->condition($db_or);
  56.       }
  57.       $db_more = db_or();
  58.       foreach ($gradids as $gradid) {
  59.           $db_more->condition('g.field_topic_grade_tid', $gradid, '=');    
  60.           $topquery->condition($db_more);
  61.       }
  62.       $topresult = $topquery->execute();
  63.       $topoptions = array();
  64.       if (!empty($form_state['values']['subject']) || !empty($form_state['values']['grade'])) {
  65.           foreach ($topresult as $toprow) {
  66.                 $topoptions[$toprow->tid] = $toprow->name;
  67.           };
  68.       }
  69.       else {
  70.          $topoptions = array();
  71.       }
  72.      
  73.        
  74.      
  75.       $form['subjectblock'] = array(
  76.             '#type'     => 'fieldset',
  77.             '#title'     => 'Subject',
  78.             '#weight'   => '12',
  79.       );  
  80.       $form['subjectblock']['subject'] = array(
  81.             '#type'     => 'checkboxes',
  82.             '#options' => $soptions,
  83.             '#prefix' => '<div style="background:#FF7F55;">',
  84.             '#suffix' => '</div>',
  85.             '#ajax' => array(
  86.                 'callback' => 'make_topic_chex_callback',
  87.                 'wrapper' => 'gunge, pow',
  88.                 'method' => 'replace',
  89.                 'progress' => array('type' => 'none'),
  90.             ),
  91.       );
  92.       $form['gradeblock'] = array(
  93.             '#type'     => 'fieldset',
  94.             '#title'     => 'Grades',
  95.             '#weight'   => '12',
  96.       );
  97.       $form['gradeblock']['grade'] = array(
  98.             '#type'     => 'checkboxes',
  99.             '#options' => $goptions,
  100.             '#prefix' => '<div style="background:#557FFF;">',
  101.             '#suffix' => '</div>',
  102.             '#ajax' => array(
  103.                 'callback' => 'make_topic_chex_callback',
  104.                 'wrapper' => 'gunge, pow',
  105.                 'method' => 'replace',
  106.                 'progress' => array('type' => 'none'),
  107.             ),
  108.       );
  109.       $form['topblock'] = array(
  110.                 '#type'     => 'fieldset',
  111.                 '#title'     => 'Topics',
  112.                 '#weight'   => '12',
  113.       );
  114.       $form['topblock']['topics'] = array(
  115.             '#type'     => 'checkboxes',
  116.             '#options' => $topoptions,
  117.             '#prefix' => '<div id="gunge" style="background:#FFAA00;">',
  118.             '#suffix' => '</div>',
  119.       );  
  120.      
  121.      
  122.      
  123.       }
  124. }
  125.  
  126.  
  127. function make_topic_chex_callback($form, $form_state) {
  128.   return $form['topblock']['topics'];
  129. }
  130.  
  131.  
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top