I am trying to remove the value(_blank) of attribute[‘target’] variable in form_state when the value I get empty i.e. when the checkbox is unselected.
public function submitForm(array &$ form, FormStateInterface $ form_state) { $ response = new AjaxResponse(); if ($ form_state->getErrors()) { unset($ form['#prefix'], $ form['#suffix']); $ form['status_messages'] = [ '#type' => 'status_messages', '#weight' => -10, ]; $ response->addCommand(new HtmlCommand('#linkit-editor-dialog-form', $ form)); } else { // This was I tried if(empty($ form_state->get('attributes')->target)){ $ form_state->setValue($ form_state['attributes']['target'], "_TEST"); #$ form_state->setValue('attributes', "_TEST"); #$ form_state->setValueForElement('target', "_TEST"); } // End $ response->addCommand(new EditorDialogSave($ form_state->getValues())); $ response->addCommand(new CloseModalDialogCommand()); } return $ response;
}
After execution the code I got wrong array
Any help? Thanks in advance.