0

I am using taxonomy manager module I want to add ajax callback to checkbox tree view for checkbox is checked condition but it is not working can some one please suggest me. I have modified the code like this

$form[$term->tid]['checkbox'] = array(
      '#type' => ($multiple) ? 'checkbox' : 'radio',
      '#title' => $term->name, // Escaping is done in theme wrappers.
      '#value' => $value,
      '#return_value' => $term->tid,
      '#ajax' => array(
        'callback' => 'ajax_example_autocheckboxes_callback',
        'wrapper' => 'checkboxes-div',
        'method' => 'replace',
        'effect' => 'fade',
      ),
      '#required' => FALSE,
      '#theme_wrappers' => ($multiple) ? array('taxonomy_manager_tree_checkbox') : array('taxonomy_manager_tree_radio'),
      '#highlight' => in_array($term->tid, $terms_to_highlight) ? TRUE : FALSE,
    );

This is the taxonomy manager module themefunction

function theme_taxonomy_manager_tree_checkbox($variables) {

  global $user;
  $element = $variables['element'];
  $element['#attributes']['type'] = 'checkbox';
  $element['#attributes']['ajax']['event'] = 'change';
  element_set_attributes($element, array('id', 'name', '#return_value' => 'value'));

  // Unchecked checkbox has #value of integer 0.
  if (!empty($element['#checked'])) {
    $element['#attributes']['checked'] = 'checked';
  }
  _form_set_class($element, array('form-checkbox'));
  $output = '<input' . drupal_attributes($element['#attributes']) . ' />';
  /* custom alter function */
  if(user_is_logged_in()){
    if(!user_access('administer taxonomy')){
      $cdms_taxonomy_id = taxonomy_term_load($element['#return_value']); 
      // echo "IF"; exit;     
    }else{
      $cdms_taxonomy_id = taxonomy_term_load($element['#return_value']);
      // echo "Else"; exit;      
    }
  }
  // echo '<pre>';print_r($variables);  echo"Term load"; print_r($cdms_taxonomy_id);  exit;
  $data = [
    'title' =>  $element['#title'],
    'tid' => @$cdms_taxonomy_id->field_cdms_txy_id[LANGUAGE_NONE][0][value],
    'count' => '',
  ];
  // Calling all modules implementing hook_my_data_alter():
  drupal_alter('my_data', $data);

  if (!in_array("Client User", array_values($user->roles))) {
  $title = $element['#title'] ."(".$data['count'].")";
}else{
   $title = $element['#title'];
}
  if (in_array("Client User", array_values($user->roles))) {
    $title = check_plain($title);
  }else{
    if (isset($element['#link'])) {
        $attr = array();
        $attr["class"][] = "term-data-link";
        $attr["class"][] = "term-data-link-id-" . $element['#return_value'];
        if (isset($element['#extra_info'])) {
          $attr["title"] = $element['#extra_info'];
        }
        $title = l($title, $element['#link'], array('attributes' => $attr));
      }
      else {
        $title = check_plain($title);
      }
  }

  $element['#children'] = '<label class="option">' . $output . ' ' . $title . '</label>';
  $element['#title_display'] = 'none';
  return theme('form_element', array('element' => $element));
}
0

ajax_example_autocheckboxes_callback function is not defined in the above code.

Also please update more info about what you are trying to do.

$form[$term->tid] = array(... 'ajax_example_autocheckboxes_callback' ...); //ajax callback
$form['tree']; //new field.

after the above function call you can get new built_info of $form_state as its rebuilt. So you can alter output of the field.

function ajax_example_autocheckboxes_callback($form, $form_state) {
  dsm($form_state);
  return $form['tree']; // this is a new field.
}

I will update my answer if more information is provided.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.