1

i have writed this code to unset empty terms :

    function shs_selective_form_alter(&$form, &$form_state, $form_id) {  

  if ($form_id == 'views_exposed_form' && $form['#id'] == 'views-exposed-form-projet-immobilier-page-1') {            
    foreach ($form['field_r_t_tid']['#options'] as $tid => $term_name) {
      if (is_numeric($tid)) {
        $result_count = db_select('taxonomy_index', 'ti')
        ->fields('ti')
        ->condition('ti.tid', $tid, '=')
        ->execute()
        ->rowCount();

        // Removing the option for tags with no-content
        if (!$result_count) {
          unset($form['field_r_t_tid']['#options'][$tid]);
        }                
      }
    }

  }
}

but is not worked, he show me this error : Undefined index : #options ... how can i resolve this error?

0

In Drupal 7 you can use field_info_field(), while in Drupal 6 you can use content_field_instance_read(), which is defined in the CCK module.

You can also use list_allowed_values().

$field = field_info_field('field_name');
$allowed_values = list_allowed_values($field);
5
  • is not working, i tried this class but it the same problem – Salaktarus Nov 21 '16 at 11:23
  • Maybe you should provide more informations than "Not working", I'm currently using those methods to get each values of select-fields onto my Drupal websites ^^' – benftwc Nov 21 '16 at 11:31
  • the only errors that it show for me is :"Warning : Invalid argument supplied for foreach()", and when i use dsm($form); i found only those result $form['field_name']['#type'], $form['field_name']['#attributes'] $form['field_name']['#default_value] – Salaktarus Nov 21 '16 at 11:35
  • <div class="form-item form-type-textfield form-item-field-r-t-tid shs-wrapper-processed"> <input class="element-invisible shs-enabled form-text shs-processed" type="text" id="edit-field-r-t-tid" name="field_r_t_tid" value="All" size="60" maxlength="128"> <select id="edit-field-r-t-tid-select-1" class="shs-select form-select shs-select-level-1" style="display: inline-block;"><option value="0">- Aucun(e) -</option> <option value="526">Kebili (0)</option><option value="523">Mahdia (0)</option> </select></div> – Salaktarus Nov 21 '16 at 11:37
  • i think is not the same select field that you use, i using a simple hierarchical select field, he has a different architecture – Salaktarus Nov 21 '16 at 11:38

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.