You are here

public function CampaignMonitorSubscriptionManager::subscribeSettingsForm in Campaign Monitor 8.2

Returns fields required for subscription form settings.

Used by subscribe block, registration form / user form.

File

src/CampaignMonitorSubscriptionManager.php, line 353

Class

CampaignMonitorSubscriptionManager
Manager for Campaignmonitor subscriptions.

Namespace

Drupal\campaignmonitor

Code

public function subscribeSettingsForm($config) {
  $lists = $this->campaignMonitorManager
    ->getLists();
  $list_options = [];
  foreach ($lists as $list_id => $list) {
    if ($this->campaignMonitorManager
      ->isListEnabled($list_id)) {
      $list_options[$list_id] = $list['name'];
    }
  }

  // A subscribe block can be for a particular list
  // Or can provide a choice of lists.
  $subscription_options = [
    'single' => $this
      ->t('Single List'),
    'user_select' => $this
      ->t('User selects list(s)'),
  ];
  $form['lists'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('List Settings'),
  ];
  $form['lists']['list'] = [
    '#type' => 'radios',
    '#options' => $subscription_options,
    '#title' => $this
      ->t('Subscription type'),
    '#description' => $this
      ->t('Single list provides a block where the user subscribes to the list you nominate.
      User select list provides a block with checkboxes for the user to choose from. Segments enables one list from which segments are available.'),
    '#default_value' => isset($config['list']) ? $config['list'] : [],
    '#attributes' => [
      'class' => [
        'list-radios',
      ],
    ],
    '#required' => TRUE,
  ];
  $form['lists']['list_id'] = [
    '#type' => 'radios',
    '#options' => $list_options,
    '#title' => $this
      ->t('List'),
    '#description' => $this
      ->t('Choose the list for this subscribe block.'),
    '#default_value' => isset($config['list_id']) ? $config['list_id'] : '',
    '#states' => [
      'visible' => [
        '.list-radios' => [
          'value' => 'single',
        ],
      ],
    ],
  ];
  $form['lists']['list_id_text'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Text'),
    '#description' => $this
      ->t('The text to accompany the subscribe block. Leave blank to provide no text. Token
      available: @name = list name.'),
    '#default_value' => isset($config['list_id_text']) ? $config['list_id_text'] : 'Subscribe to the @name list',
    '#states' => [
      'visible' => [
        '.list-radios' => [
          'value' => 'single',
        ],
      ],
    ],
  ];
  return $form;
}