You are here

private function MailchimpCampaignForm::buildOptionList in Mailchimp 2.x

Same name and namespace in other branches
  1. 8 modules/mailchimp_campaign/src/Form/MailchimpCampaignForm.php \Drupal\mailchimp_campaign\Form\MailchimpCampaignForm::buildOptionList()

Returns an options list for a given array of items.

Parameters

array $list: Array of item data containing 'id' and 'name' properties.

string $no_selection_label: The option value to display when no option is selected.

array $labels: Optional associative array of list indexes to custom labels.

Return value

array Associative array of item IDs to name.

1 call to MailchimpCampaignForm::buildOptionList()
MailchimpCampaignForm::form in modules/mailchimp_campaign/src/Form/MailchimpCampaignForm.php
Gets the actual form array to be built.

File

modules/mailchimp_campaign/src/Form/MailchimpCampaignForm.php, line 585

Class

MailchimpCampaignForm
Form controller for the MailchimpCampaign entity edit form.

Namespace

Drupal\mailchimp_campaign\Form

Code

private function buildOptionList(array $list, $no_selection_label = '-- Select --', array $labels = []) {
  $options = [];
  if ($no_selection_label) {
    $options[''] = $no_selection_label;
  }
  foreach ($list as $index => $item) {
    if (!isset($item->id)) {
      $label = isset($labels[$index]) ? $labels[$index] : $index;
      if (count($item)) {
        $options[$label] = $this
          ->buildOptionList($item, FALSE, $labels);
      }
    }
    else {
      $options[$item->id] = $item->name;
    }
  }
  return $options;
}