public function MappedObjectForm::submitPull in Salesforce Suite 5.0.x
Same name and namespace in other branches
- 8.4 modules/salesforce_mapping_ui/src/Form/MappedObjectForm.php \Drupal\salesforce_mapping_ui\Form\MappedObjectForm::submitPull()
Submit handler for "pull" button.
File
- modules/
salesforce_mapping_ui/ src/ Form/ MappedObjectForm.php, line 214
Class
- MappedObjectForm
- Salesforce Mapping Form base.
Namespace
Drupal\salesforce_mapping_ui\FormCode
public function submitPull(array &$form, FormStateInterface $form_state) {
$mapping_id = $form_state
->getValue([
'salesforce_mapping',
0,
'target_id',
]);
$sfid = new SFID($form_state
->getValue([
'salesforce_id',
0,
'value',
]));
$mapped_object = $this->entity
->set('salesforce_id', (string) $sfid)
->set('salesforce_mapping', $mapping_id);
// Create stub entity.
$drupal_entity_array = $form_state
->getValue([
'drupal_entity',
0,
]);
if ($drupal_entity_array['target_id']) {
$drupal_entity = $this->entityTypeManager
->getStorage($drupal_entity_array['target_type'])
->load($drupal_entity_array['target_id']);
$mapped_object
->set('drupal_entity', $drupal_entity);
}
else {
$drupal_entity = $this->entityTypeManager
->getStorage($drupal_entity_array['target_type'])
->create([
'salesforce_pull' => TRUE,
]);
$mapped_object
->set('drupal_entity', NULL);
$mapped_object
->setDrupalEntityStub($drupal_entity);
}
try {
// Pull from SF. Save first to pass local validation.
$mapped_object
->save();
$mapped_object
->pull();
} catch (\Exception $e) {
$this->eventDispatcher
->dispatch(new SalesforceErrorEvent($e), SalesforceEvents::ERROR);
$this
->messenger()
->addError($this
->t('Pull failed with an exception: %exception', [
'%exception' => $e
->getMessage(),
]));
$form_state
->setRebuild();
return;
}
// @TODO: more verbose feedback for successful pull.
$this
->messenger()
->addStatus('Pull successful.');
$form_state
->setRedirect('entity.salesforce_mapped_object.canonical', [
'salesforce_mapped_object' => $mapped_object
->id(),
]);
}