Ajouter un commentaire

Hello

I managed to make it work for Drupal 8. But I am stuck on the AJAX part.

Each time I try to change my first select throws me an error :

An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (2G) that this server supports.

What am I missing ?
Here is my code

<?php


function filt_form_views_exposed_form_alter(&$form, $form_state){
 
//dpm($form);

 
if ($form['#id'] == 'views-exposed-form-filtres-page-1') {

     
//kint($form_state);

     
$selectedTypeRaccordement = $form_state->getValue('field_type_de_raccordement_target_id');

   
$form['field_composants_target_id']['#options'] = _get_associative_array_from_view(
     
'filtres_exposes', // view id
     
'default', // view display id
     
'taxonomy_term_field_data_node__field_composants_tid', // key field id
     
'taxonomy_term_field_data_node__field_composants_name', // value field id
     
$selectedTypeRaccordement // term id of the selected shape
   
);


   
$form['field_type_de_raccordement_target_id']['#ajax'] = array(
     
'callback' => '_update_composants_callback',
     
'wrapper' => 'composants_wrapper',
    );

   
$form['field_composants_target_id']['#prefix'] = '<div id="composants_wrapper">';
   
$form['field_composants_target_id']['#suffix'] = '</div>';

   
  }
}

?>


<?php

function _get_associative_array_from_view($viewID, $viewDisplayID, $keyFieldID, $valueFieldID){
 
 
$associativeArray = array();
 
$associativeArray['All'] = t('- Any -');

 
$viewResults = views_get_view_result($viewID, $viewDisplayID);
 
//dpm($viewResults);
 
 
foreach($viewResults as $viewRow) {
   
$associativeArray[$viewRow->$keyFieldID] = $viewRow->$valueFieldID;
  }
 
  return
$associativeArray;
}
?>


<?php

function _update_composants_callback($form, $form_state) {
  return
$form['field_composants_target_id'];
}

?>