You are here

public function MailchimpEcommerceCommerceAdminSettings::buildForm in Mailchimp E-Commerce 8

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 MailchimpEcommerceAdminSettings::buildForm

File

modules/mailchimp_ecommerce_commerce/src/Form/MailchimpEcommerceCommerceAdminSettings.php, line 70

Class

MailchimpEcommerceCommerceAdminSettings

Namespace

Drupal\mailchimp_ecommerce_commerce\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildForm($form, $form_state);

  // This is the currently active store according to Drupal Commerce.
  // Commerce allows multiple stores in D8 - may need to consider that here.
  $store = $this->store_context
    ->getStore();
  if (!empty($store)) {

    // Set default currency code for the Mailchimp store.
    $default_currency = $store
      ->getDefaultCurrencyCode();
    if (isset($form['mailchimp_ecommerce_currency']['#options'][$default_currency])) {
      $form['mailchimp_ecommerce_currency']['#default_value'] = $default_currency;
    }
  }

  // Identify Drupal Commerce to Mailchimp.
  $form['platform']['#default_value'] = 'Drupal Commerce';
  return $form;
}