public function CustomSearchAdBlock::blockForm in Google AdSense integration 8
Overrides BlockPluginTrait::blockForm
File
- src/
Plugin/ Block/ CustomSearchAdBlock.php, line 100
Class
- CustomSearchAdBlock
- Provides an AdSense Custom Search ad block.
Namespace
Drupal\adsense\Plugin\BlockCode
public function blockForm($form, FormStateInterface $form_state) {
// Hide block title by default.
$form['label_display']['#default_value'] = FALSE;
$link = Link::fromTextAndUrl($this
->t('Google AdSense account page'), Url::fromUri('https://www.google.com/adsense/app#main/myads-springboard'))
->toString();
$form['ad_slot'] = [
'#type' => 'textfield',
'#title' => $this
->t('Ad ID'),
'#default_value' => $this->configuration['ad_slot'],
'#description' => $this
->t('This is the Ad ID from your @adsensepage, such as 1234567890.', [
'@adsensepage' => $link,
]),
'#required' => TRUE,
];
$default = $this->configuration['version'];
if (empty($this->configuration['version'])) {
// If the block has already been saved, but the version is not set, that
// means it's a version 1, otherwise set to the latest version (2).
$default = empty($this->configuration['ad_slot']) ? '2' : '1';
}
$form['version'] = [
'#type' => 'radios',
'#title' => $this
->t('CSE Version'),
'#default_value' => $default,
'#options' => [
'1' => $this
->t('Version 1'),
'2' => $this
->t('Version 2'),
],
'#description' => $this
->t('CSE version. If unsure, choose %default.', [
'%default' => 'Version 2',
]),
'#required' => TRUE,
];
return $form;
}