public function MappedObjectForm::buildForm 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::buildForm()
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides EntityForm::buildForm
File
- modules/
salesforce_mapping_ui/ src/ Form/ MappedObjectForm.php, line 103
Class
- MappedObjectForm
- Salesforce Mapping Form base.
Namespace
Drupal\salesforce_mapping_ui\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
// Include the parent entity on the form.
$form = parent::buildForm($form, $form_state);
$entity_id = $entity_type_id = FALSE;
if ($this->entity
->isNew()) {
if ($drupal_entity = $this
->getDrupalEntityFromUrl()) {
$form['drupal_entity']['widget'][0]['target_type']['#default_value'] = $drupal_entity
->getEntityTypeId();
$form['drupal_entity']['widget'][0]['target_id']['#default_value'] = $drupal_entity;
}
}
// Allow exception to bubble up here, because we shouldn't have got here if
// there isn't a mapping.
// If entity is not set, entity types are dependent on available mappings.
$mappings = $this->mappingStorage
->loadMultiple();
// @TODO #states for entity-type + salesforce mapping dependency
if ($mappings) {
$options = array_keys($mappings);
// Filter options based on drupal entity type.
$form['salesforce_mapping']['widget']['#options'] = array_intersect_key($form['salesforce_mapping']['widget']['#options'], array_flip($options));
}
$form['actions']['push'] = [
'#type' => 'submit',
'#value' => $this
->t('Push'),
'#weight' => 5,
'#submit' => [
[
$this,
'submitPush',
],
],
'#validate' => [
[
$this,
'validateForm',
],
[
$this,
'validatePush',
],
],
];
$form['actions']['pull'] = [
'#type' => 'submit',
'#value' => $this
->t('Pull'),
'#weight' => 6,
'#submit' => [
[
$this,
'submitPull',
],
],
'#validate' => [
[
$this,
'validateForm',
],
[
$this,
'validatePull',
],
],
];
return $form;
}