public function ModalForm::addItemsAjax in Entity Reference View Widget 8
Ajax callback for the the add items button.
File
- src/
Form/ ModalForm.php, line 58 - Contains \Drupal\entity_reference_view_widget\Form\ModalForm.
Class
- ModalForm
- Provides the database logging filter form.
Namespace
Drupal\entity_reference_view_widget\FormCode
public function addItemsAjax(array $form, FormStateInterface &$form_state) {
$response = new AjaxResponse();
$input = $form_state
->getUserInput();
$messages = drupal_get_messages('error', FALSE);
if (!empty($messages)) {
$status_messages = array(
'#theme' => 'status_messages',
'#display' => 'error',
);
$response
->addCommand(new RemoveCommand('#drupal-modal .messages'));
$response
->addCommand(new PrependCommand('#drupal-modal', drupal_render($status_messages)));
}
else {
if (!empty($input['entity_ids'])) {
$settings = $form_state
->get('ervw_settings');
$rows = ViewWidget::getRows($input['entity_ids'], $settings);
$response
->addCommand(new ReplaceCommand('#' . $settings['wrapper'] . ' > tbody', '<tbody>' . drupal_render($rows) . '</tbody>'));
// Close the modal if the widget setting has been selected.
if (!empty($settings['close_modal'])) {
$response
->addCommand(new CloseModalDialogCommand());
}
}
}
return $response;
}