public function ContentUploadSelectForm::submitForm in GatherContent 8.5
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_upload_ui/
src/ Form/ ContentUploadSelectForm.php, line 367
Class
- ContentUploadSelectForm
- Class ContentUpdateSelectForm.
Namespace
Drupal\gathercontent_upload_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');
$selectedEntities = [];
foreach ($form_state
->getValue('entities') as $key => $data) {
if ($data['data']['selected'] === '1') {
$selectedEntities[$key] = [
'id' => $data['data']['entity_id'],
'entity_type' => $data['data']['entity_type'],
'gc_id' => $data['data']['gc_id'],
'mapping_id' => $data['data']['mapping_id'],
];
}
}
$this->entities = $selectedEntities;
$this->step = 2;
$form_state
->setRebuild(TRUE);
}
elseif ($this->step === 2) {
$operations = [];
$uploadContent = $this->entities;
foreach ($uploadContent as $data) {
/** @var \Drupal\gathercontent\Entity\MappingInterface $mapping */
$mapping = Mapping::load($data['mapping_id']);
$storage = $this->entityTypeManager
->getStorage($data['entity_type']);
$entity = $storage
->load($data['id']);
$operations[] = [
'gathercontent_upload_process',
[
$entity,
$mapping,
$data['gc_id'],
],
];
}
$operations[] = [
'gathercontent_upload_migrate_update_process',
[],
];
$batch = [
'title' => $this
->t('Uploading content ...'),
'operations' => $operations,
'finished' => 'gathercontent_upload_finished',
'file' => drupal_get_path('module', 'gathercontent_upload_ui') . '/gathercontent_upload_ui.module',
'init_message' => $this
->t('Upload is starting ...'),
'progress_message' => $this
->t('Processed @current out of @total.'),
'error_message' => $this
->t('An error occurred during processing'),
'progressive' => TRUE,
];
batch_set($batch);
}
}
elseif ($form_state
->getTriggeringElement()['#id'] === 'edit-back') {
if ($this->step === 1) {
return $form_state
->setRedirect('gathercontent_upload_ui.upload_select_form');
}
$this->step = 1;
$form_state
->setRebuild(TRUE);
}
return TRUE;
}