Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function nodeform_form_alter(&$form, &$form_state, $form_id) {
- if ($form_id == 'article_node_form') {
- $form['#prefix'] = '<div style="background:#AAFF55;">';
- $form['#suffix'] = '</div>';
- $form['actions']['submit']['#value'] = t('Hammering');
- $form['title']['#default_value'] = t('Dance');
- $form['title']['#required'] = FALSE;
- $squery = db_select('taxonomy_term_data', 't');
- $squery
- ->fields('t', array('vid', 'name', 'tid', 'weight'))
- ->condition('t.vid', 2, '=')
- ->orderBy('t.weight', 'ASC');
- $sresult = $squery->execute();
- $soptions = array();
- foreach ($sresult as $srow) {
- $soptions[$srow->tid] = $srow->name;
- };
- $gquery = db_select('taxonomy_term_data', 't');
- $gquery
- ->fields('t', array('vid', 'name', 'tid', 'weight'))
- ->condition('t.vid', 3, '=')
- ->orderBy('t.weight', 'ASC');
- $gresult = $gquery->execute();
- $goptions = array();
- foreach ($gresult as $grow) {
- $goptions[$grow->tid] = $grow->name;
- };
- $subjids = array();
- if (!empty($form_state['values']['subject'])) {
- $subjids = array_filter($form_state['values']['subject']);
- }
- $gradids = array();
- if (!empty($form_state['values']['grade'])) {
- $gradids = array_filter($form_state['values']['grade']);
- }
- $topquery = db_select('taxonomy_term_data', 't');
- $topquery->join('field_data_field_topic_subject', 's', 't.tid = s.entity_id');
- $topquery->join(' field_data_field_topic_grade', 'g', 't.tid = g.entity_id');
- $topquery->fields('t', array('vid', 'name', 'tid'));
- $topquery->fields('s', array('field_topic_subject_tid'));
- $topquery->fields('g', array('field_topic_grade_tid'));
- $db_or = db_or();
- foreach ($subjids as $subjid) {
- $db_or->condition('s.field_topic_subject_tid', $subjid, '=');
- $topquery->condition($db_or);
- }
- $db_more = db_or();
- foreach ($gradids as $gradid) {
- $db_more->condition('g.field_topic_grade_tid', $gradid, '=');
- $topquery->condition($db_more);
- }
- $topresult = $topquery->execute();
- $topoptions = array();
- if (!empty($form_state['values']['subject']) || !empty($form_state['values']['grade'])) {
- foreach ($topresult as $toprow) {
- $topoptions[$toprow->tid] = $toprow->name;
- };
- }
- else {
- $topoptions = array();
- }
- $form['subjectblock'] = array(
- '#type' => 'fieldset',
- '#title' => 'Subject',
- '#weight' => '12',
- );
- $form['subjectblock']['subject'] = array(
- '#type' => 'checkboxes',
- '#options' => $soptions,
- '#prefix' => '<div style="background:#FF7F55;">',
- '#suffix' => '</div>',
- '#ajax' => array(
- 'callback' => 'make_topic_chex_callback',
- 'wrapper' => 'gunge, pow',
- 'method' => 'replace',
- 'progress' => array('type' => 'none'),
- ),
- );
- $form['gradeblock'] = array(
- '#type' => 'fieldset',
- '#title' => 'Grades',
- '#weight' => '12',
- );
- $form['gradeblock']['grade'] = array(
- '#type' => 'checkboxes',
- '#options' => $goptions,
- '#prefix' => '<div style="background:#557FFF;">',
- '#suffix' => '</div>',
- '#ajax' => array(
- 'callback' => 'make_topic_chex_callback',
- 'wrapper' => 'gunge, pow',
- 'method' => 'replace',
- 'progress' => array('type' => 'none'),
- ),
- );
- $form['topblock'] = array(
- '#type' => 'fieldset',
- '#title' => 'Topics',
- '#weight' => '12',
- );
- $form['topblock']['topics'] = array(
- '#type' => 'checkboxes',
- '#options' => $topoptions,
- '#prefix' => '<div id="gunge" style="background:#FFAA00;">',
- '#suffix' => '</div>',
- );
- }
- }
- function make_topic_chex_callback($form, $form_state) {
- return $form['topblock']['topics'];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement