public function CampaignMonitorSubscribeBlock::blockForm in Campaign Monitor 8
Same name and namespace in other branches
- 8.2 src/Plugin/Block/CampaignMonitorSubscribeBlock.php \Drupal\campaignmonitor\Plugin\Block\CampaignMonitorSubscribeBlock::blockForm()
Returns the configuration form elements specific to this block plugin.
Blocks that need to add form elements to the normal block configuration form should implement this method.
Parameters
array $form: The form definition array for the block configuration form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The renderable form array representing the entire configuration form.
Overrides BlockPluginTrait::blockForm
File
- src/
Plugin/ Block/ CampaignMonitorSubscribeBlock.php, line 24
Class
- CampaignMonitorSubscribeBlock
- Provides a 'Subscribe' block.
Namespace
Drupal\campaignmonitor\Plugin\BlockCode
public function blockForm($form, FormStateInterface $form_state) {
$form = parent::blockForm($form, $form_state);
$config = $this
->getConfiguration();
$lists = campaignmonitor_get_lists();
$list_options = [];
foreach ($lists as $list_id => $list) {
$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['campaignmonitor'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Settings'),
];
$form['campaignmonitor']['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.'),
'#default_value' => isset($config['list']) ? $config['list'] : [],
'#attributes' => [
'class' => [
'list-radios',
],
],
'#required' => TRUE,
];
$form['campaignmonitor']['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['campaignmonitor']['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;
}