public function ContentImportSelectForm::submitForm in GatherContent 8.3
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormInterface::submitForm
File
- src/
Form/ ContentImportSelectForm.php, line 420
Class
- ContentImportSelectForm
- Class ContentImportSelectForm.
Namespace
Drupal\gathercontent\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
if ($form_state
->getTriggeringElement()['#id'] === 'edit-submit') {
if ($this->step === 1) {
$this->projectId = $form_state
->getValue('project');
$selected_nodes = [];
$selected_menus = [];
$selected_statuses = [];
foreach ($form_state
->getValue('items') as $item_id => $item) {
if ($item['selected'] === "1") {
$selected_nodes[] = $item_id;
$selected_menus[$item_id] = $item['menu'];
$selected_statuses[$item_id] = $item['drupal_status'];
}
}
$this->nodes = $selected_nodes;
$this->menu = $selected_menus;
$this->drupalStatus = $selected_statuses;
$this->step = 2;
$form_state
->setRebuild(TRUE);
}
elseif ($this->step === 2) {
$operation = Operation::create([
'type' => 'import',
]);
$operation
->save();
$operations = [];
$stack = [];
$import_content = $this->nodes;
foreach ($import_content as $k => $value) {
if (isset($this->menu[$value]) && $this->menu[$value] != -1 || !isset($this->menu[$value])) {
$parent_menu_item = isset($this->menu[$value]) ? $this->menu[$value] : NULL;
$drupal_status = isset($this->drupalStatus[$value]) ? $this->drupalStatus[$value] : 0;
$operations[] = [
'gathercontent_import_process',
[
$value,
$form_state
->getValue('status'),
$operation
->uuid(),
$drupal_status,
$form_state
->getValue('node_update_method'),
$parent_menu_item,
],
];
$stack[$value] = $value;
unset($import_content[$k]);
}
}
if (!empty($import_content)) {
// Load all by project_id.
$content_obj = new Content();
$contents_source = $content_obj
->getContents($this->projectId);
$content = [];
foreach ($contents_source as $value) {
$content[$value->id] = $value;
}
while (!empty($import_content)) {
$current = reset($import_content);
if (isset($stack[$content[$current]->parent_id])) {
$parent_menu_item = 'node:' . $content[$current]->parent_id;
$drupal_status = isset($this->drupalStatus[$current]) ? $this->drupalStatus[$current] : 0;
$operations[] = [
'gathercontent_import_process',
[
$current,
$form_state
->getValue('status'),
$operation
->uuid(),
$drupal_status,
$form_state
->getValue('node_update_method'),
$parent_menu_item,
],
];
$stack[$current] = $current;
array_shift($import_content);
}
else {
array_shift($import_content);
array_push($import_content, $current);
}
}
}
$batch = [
'title' => t('Importing content ...'),
'operations' => $operations,
'finished' => 'gathercontent_import_finished',
'file' => drupal_get_path('module', 'gathercontent') . '/gathercontent.module',
'init_message' => t('Import is starting ...'),
'progress_message' => t('Processed @current out of @total.'),
'error_message' => t('An error occurred during processing'),
];
batch_set($batch);
}
}
elseif ($form_state
->getTriggeringElement()['#id'] === 'edit-back') {
if ($this->step === 1) {
return $form_state
->setRedirect('gathercontent.import_select_form');
}
$this->step = 1;
$form_state
->setRebuild(TRUE);
}
return TRUE;
}