public function ContentImportSelectForm::submitForm in GatherContent 8.5
Same name and namespace in other branches
- 8.4 gathercontent_ui/src/Form/ContentImportSelectForm.php \Drupal\gathercontent_ui\Form\ContentImportSelectForm::submitForm()
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
- gathercontent_ui/
src/ Form/ ContentImportSelectForm.php, line 464
Class
- ContentImportSelectForm
- Class ContentImportSelectForm.
Namespace
Drupal\gathercontent_ui\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');
$selectedNodes = [];
$selectedMenus = [];
$selectedStatuses = [];
foreach ($form_state
->getValue('items') as $item_id => $item) {
if ($item['selected'] === "1") {
$selectedNodes[] = $item_id;
$selectedStatuses[$item_id] = $item['drupal_status'];
if (!empty($item['menu'])) {
$selectedMenus[$item_id] = $item['menu'];
}
}
}
$this->nodes = $selectedNodes;
$this->menu = $selectedMenus;
$this->drupalStatus = $selectedStatuses;
$this->step = 2;
$form_state
->setRebuild(TRUE);
}
elseif ($this->step === 2) {
$operations = [];
$importContent = $this->nodes;
$gcIds = [];
$importOptions = [];
foreach ($importContent as $value) {
/** @var \Cheppers\GatherContent\DataTypes\Item $item */
$gcItem = $this->client
->itemGet($value);
/** @var \Drupal\gathercontent\Entity\MappingInterface $mapping */
$mapping = MappingLoader::load($gcItem);
$mappingId = $mapping
->id();
$parentMenuItem = isset($this->menu[$value]) ? $this->menu[$value] : NULL;
$drupalStatus = isset($this->drupalStatus[$value]) ? $this->drupalStatus[$value] : 0;
$importOptions[$mappingId][$value] = new ImportOptions($drupalStatus, $form_state
->getValue('node_create_new_revision'), $form_state
->getValue('status'), $parentMenuItem);
if (!empty($value) && (!isset($gcIds[$mappingId]) || !array_search($value, $gcIds[$mappingId]))) {
$gcIds[$mappingId][] = $value;
}
$operations[$mappingId] = [
'gathercontent_import_process',
[
$gcIds[$mappingId],
$importOptions[$mappingId],
$mapping,
],
];
}
$batch = [
'title' => $this
->t('Importing content ...'),
'operations' => $operations,
'finished' => 'gathercontent_ui_import_finished',
'file' => drupal_get_path('module', 'gathercontent') . '/gathercontent.module',
'init_message' => $this
->t('Import is starting ...'),
'progress_message' => $this
->t('Processed @current out of @total.'),
'error_message' => $this
->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_ui.import_select_form');
}
$this->step = 1;
$form_state
->setRebuild(TRUE);
}
return TRUE;
}