You are here

public function MappedObjectForm::buildForm in Salesforce Suite 8.3

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/src/Form/MappedObjectForm.php, line 103

Class

MappedObjectForm
Salesforce Mapping Form base.

Namespace

Drupal\salesforce_mapping\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  // Include the parent entity on the form.
  $form = parent::buildForm($form, $form_state);
  $drupal_entity = $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' => t('Push'),
    '#weight' => 5,
    '#submit' => [
      [
        $this,
        'submitPush',
      ],
    ],
    '#validate' => [
      [
        $this,
        'validateForm',
      ],
      [
        $this,
        'validatePush',
      ],
    ],
  ];
  $form['actions']['pull'] = [
    '#type' => 'submit',
    '#value' => t('Pull'),
    '#weight' => 6,
    '#submit' => [
      [
        $this,
        'submitPull',
      ],
    ],
    '#validate' => [
      [
        $this,
        'validateForm',
      ],
      [
        $this,
        'validatePull',
      ],
    ],
  ];
  return $form;
}