public function FeedTypeForm::ajaxCallback in Feeds 8.3
Sends an ajax response.
File
- src/
FeedTypeForm.php, line 368
Class
- FeedTypeForm
- Form controller for the feed type edit forms.
Namespace
Drupal\feedsCode
public function ajaxCallback(array $form, FormStateInterface $form_state) {
$type = $form_state
->getTriggeringElement()['#plugin_type'];
$response = new AjaxResponse();
// Set URL hash so that the correct settings tab is open.
if (isset($form[$type . '_configuration']['#id'])) {
$hash = ltrim($form[$type . '_configuration']['#id'], '#');
$response
->addCommand(new SetHashCommand($hash));
}
// Update the forms.
$plugin_settings = $this->renderer
->renderRoot($form['plugin_settings']);
$advanced_settings = $this->renderer
->renderRoot($form[$type . '_wrapper']['advanced']);
$response
->addCommand(new ReplaceCommand('#feeds-ajax-form-wrapper', $plugin_settings));
$response
->addCommand(new ReplaceCommand('#feeds-plugin-' . $type . '-advanced', $advanced_settings));
// Add attachments.
$attachments = NestedArray::mergeDeep($form['plugin_settings']['#attached'], $form[$type . '_wrapper']['advanced']['#attached']);
$response
->setAttachments($attachments);
// Display status messages.
$status_messages = [
'#type' => 'status_messages',
];
$output = $this->renderer
->renderRoot($status_messages);
if (!empty($output)) {
$response
->addCommand(new HtmlCommand('.region-messages', $output));
}
return $response;
}