0

Inline entity form is using in bricks.
In that Inline entity form, there is 2 dropdown fields available . i want to form alter in that Inline entity form, so that selection of one dropdown value, second will change.
To fire Ajax call i have used hook_inline_entity_form_entity_form_alter().
On loading of form it is working fine, but when Ajax callback invoked i think hook_inline_entity_form_entity_form_alter() is not loading again.
it is throwing error

TypeError: Argument 1 passed to Drupal\Core\Render\MainContent\AjaxRenderer::renderResponse() must be of the type array, null given.

not sure Ajax call worked in form alter of inline entity form.

Below is source code:

function customcheck_inline_entity_form_entity_form_alter(&$entity_form,  &$form_state) {


if($entity_form['#entity_type'] == 'brick' && $entity_form['#bundle'] == 'role') {
   $selected = ($form_state->getValue('dropdown_one')) ? $form_state->getValue('dropdown_one') : 0;

   $entity_form['dropdown_one'] = [ 
    '#type' => 'select',
    '#title' => 'My Test',
    '#options' => firstOptions(),
    '#default_value' => $selected,
    '#ajax' => [
        'event' => 'change',
    'callback' => 'newfunctionCheck',
    'wrapper' => 'edit-output123',
    'progress' => [
        'type' => 'throbber',
        'message' => 'Verifying entry...',        ],
    ]
   ];

  $entity_form['dropdown_second'] = [
    '#type' => 'select', 
    '#title' => t('Instruments'),
    '#prefix' => '<div id="edit-output123">', 
    '#suffix' => '</div>',
    '#options' => getData($selected), 
    '#default_value' => $form_state->getValue('dropdown_second') ? $form_state->getValue('dropdown_second') : '',
  ];


  }
}


function newfunctionCheck(&$entity_form, FormStateInterface $form_state) {
  return $entity_form['dropdown_second'];
}

function getData($key = '') {
  $options = [
    '90' => ['34' => 'test'],
    '91' => ['24' => 'new test'],
    '92' => ['14' => 'my hckeck'],
  ];
  if(isset($key)) {
      return $options[$key];  
  } else {
      return array();
  }
  return $options;    
}

function firstOptions() {
  $options = [
      '90' => 'test 122',
      '91' => 'new test 33',
      '92' => 'my hckeck 45',
  ];
  return $options; 
}
  • 1
    it would be best if you share your code as could be alot of stuff going on in there that could cause issues – Taggart Jensen Dec 5 '19 at 22:54
  • I have added source code of form alter for inline entity form. – Kamlesh Patidar Dec 6 '19 at 4:58

Your Answer

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

Browse other questions tagged or ask your own question.