CampaignMonitorRegistrationAdminForm.php in Campaign Monitor 8.2
File
modules/campaignmonitor_registration/src/Form/CampaignMonitorRegistrationAdminForm.php
View source
<?php
namespace Drupal\campaignmonitor_registration\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\campaignmonitor\CampaignMonitorSubscriptionManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
class CampaignMonitorRegistrationAdminForm extends ConfigFormBase {
protected $campaignMonitorSubscriptionManager;
public function __construct(CampaignMonitorSubscriptionManager $campaignmonitor_subscription_manager) {
$this->campaignMonitorSubscriptionManager = $campaignmonitor_subscription_manager;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('campaignmonitor.subscription_manager'));
}
public function getFormId() {
return 'campaignmonitor_registration_admin_settings';
}
protected function getEditableConfigNames() {
return [
'campaignmonitor_registration.settings',
];
}
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('campaignmonitor_registration.settings');
$form['checkbox_text'] = [
'#type' => 'textarea',
'#title' => $this
->t('Registration text'),
'#description' => $this
->t('The text to use by the checkbox that reveals the newsletter lists'),
'#default_value' => $config
->get('checkbox_text'),
];
$form += $this->campaignMonitorSubscriptionManager
->subscribeSettingsForm($config
->getRawData());
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this
->config('campaignmonitor_registration.settings');
$config
->set('checkbox_text', $form_state
->getValue('checkbox_text'))
->set('list', $form_state
->getValue('list'))
->set('list_id', $form_state
->getValue('list_id'))
->set('list_id_text', $form_state
->getValue('list_id_text'))
->save();
parent::submitForm($form, $form_state);
}
}