View source
<?php
namespace Drupal\tacjs\Form\Steps;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class ManageDialog extends ConfigFormBase {
public function getFormId() {
return 'tacjs_manage_dialog';
}
protected function getEditableConfigNames() {
return [
'tacjs.settings',
];
}
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('tacjs.settings');
$form['privacyUrl'] = [
'#type' => 'textfield',
'#title' => $this
->t('Privacy url'),
'#description' => $this
->t('Privacy policy url'),
'#default_value' => $config
->get('dialog.privacyUrl'),
];
$form['cookieName'] = [
'#type' => 'textfield',
'#title' => $this
->t('Cookie name'),
'#default_value' => $config
->get('dialog.cookieName'),
];
$form['hashtag'] = [
'#type' => 'textfield',
'#title' => $this
->t('Hashtag'),
'#description' => $this
->t('Open the panel with this hashtag'),
'#default_value' => $config
->get('dialog.hashtag'),
];
$form['orientation'] = [
'#type' => 'radios',
'#title' => $this
->t('Orientation'),
'#description' => $this
->t('Banner position (top - bottom)'),
'#default_value' => $config
->get('dialog.orientation'),
'#options' => [
'top' => $this
->t('Top'),
'middle' => t('Middle'),
'bottom' => $this
->t('Bottom'),
],
];
$form['bodyPosition'] = [
'#type' => 'radios',
'#title' => $this
->t('bodyPosition'),
'#description' => $this
->t('Body position (top - bottom)'),
'#default_value' => $config
->get('dialog.bodyPosition'),
'#options' => [
'top' => $this
->t('Top'),
'bottom' => $this
->t('Bottom'),
],
];
$form['showAlertSmall'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Show alert small'),
'#description' => $this
->t('Show the small banner on bottom right'),
'#default_value' => $config
->get('dialog.showAlertSmall'),
];
$form['cookieslist'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Cookies list'),
'#description' => $this
->t('Show the cookie list'),
'#default_value' => $config
->get('dialog.cookieslist'),
];
$form['adblocker'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Adblocker'),
'#description' => $this
->t('Show a Warning if an adblocker is detected'),
'#default_value' => $config
->get('dialog.adblocker'),
];
$form['AcceptAllCta'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Accept all cta'),
'#description' => $this
->t('Show the accept all button when high privacy on'),
'#default_value' => $config
->get('dialog.AcceptAllCta'),
];
$form['highPrivacy'] = [
'#type' => 'checkbox',
'#title' => $this
->t('High privacy'),
'#description' => $this
->t('Disable auto consent'),
'#default_value' => $config
->get('dialog.highPrivacy'),
];
$form['handleBrowserDNTRequest'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Handle browser DNT request'),
'#description' => $this
->t('If Do Not Track == 1, disallow all'),
'#default_value' => $config
->get('dialog.handleBrowserDNTRequest'),
];
$form['removeCredit'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Remove credit'),
'#description' => $this
->t('Remove credit link'),
'#default_value' => $config
->get('dialog.removeCredit'),
];
$form['moreInfoLink'] = [
'#type' => 'checkbox',
'#title' => $this
->t('More info link'),
'#description' => $this
->t('Show more info link'),
'#default_value' => $config
->get('dialog.moreInfoLink'),
];
$form['useExternalCss'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Use external CSS'),
'#default_value' => $config
->get('dialog.useExternalCss'),
];
$form['useExternalJs'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Use external JS'),
'#default_value' => $config
->get('dialog.useExternalJs'),
];
$form['cookieDomain'] = [
'#type' => 'textarea',
'#title' => $this
->t('Cookie domain'),
'#description' => $this
->t('Shared cookie for subdomain website'),
'#default_value' => $config
->get('dialog.cookieDomain'),
];
$form['readmoreLink'] = [
'#type' => 'textfield',
'#title' => $this
->t('Read more link'),
'#description' => $this
->t('Change the default readmore link pointing to opt-out.ferank.eu'),
'#default_value' => $config
->get('dialog.readmoreLink'),
];
return parent::buildForm($form, $form_state);
}
public function validateForm(array &$form, FormStateInterface $form_state) {
$form_state
->setValue('showAlertSmall', $form_state
->getValue('showAlertSmall') ? TRUE : FALSE)
->setValue('cookieslist', $form_state
->getValue('cookieslist') ? TRUE : FALSE)
->setValue('adblocker', $form_state
->getValue('adblocker') ? TRUE : FALSE)
->setValue('AcceptAllCta', $form_state
->getValue('AcceptAllCta') ? TRUE : FALSE)
->setValue('highPrivacy', $form_state
->getValue('highPrivacy') ? TRUE : FALSE)
->setValue('handleBrowserDNTRequest', $form_state
->getValue('handleBrowserDNTRequest') ? TRUE : FALSE)
->setValue('removeCredit', $form_state
->getValue('removeCredit') ? TRUE : FALSE)
->setValue('moreInfoLink', $form_state
->getValue('moreInfoLink') ? TRUE : FALSE)
->setValue('useExternalCss', $form_state
->getValue('useExternalCss') ? TRUE : FALSE)
->setValue('useExternalJs', $form_state
->getValue('useExternalJs') ? TRUE : FALSE);
parent::validateForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this
->config('tacjs.settings');
$config
->set('dialog.adblocker', $form_state
->getValue('adblocker'))
->set('dialog.hashtag', $form_state
->getValue('hashtag'))
->set('dialog.cookieName', $form_state
->getValue('cookieName'))
->set('dialog.highPrivacy', $form_state
->getValue('highPrivacy'))
->set('dialog.orientation', $form_state
->getValue('orientation'))
->set('dialog.bodyPosition', $form_state
->getValue('bodyPosition'))
->set('dialog.removeCredit', $form_state
->getValue('removeCredit'))
->set('dialog.showAlertSmall', $form_state
->getValue('showAlertSmall'))
->set('dialog.cookieslist', $form_state
->getValue('cookieslist'))
->set('dialog.handleBrowserDNTRequest', $form_state
->getValue('handleBrowserDNTRequest'))
->set('dialog.AcceptAllCta', $form_state
->getValue('AcceptAllCta'))
->set('dialog.moreInfoLink', $form_state
->getValue('moreInfoLink'))
->set('dialog.privacyUrl', $form_state
->getValue('privacyUrl'))
->set('dialog.useExternalCss', $form_state
->getValue('useExternalCss'))
->set('dialog.useExternalJs', $form_state
->getValue('useExternalJs'))
->set('dialog.cookieDomain', $form_state
->getValue('cookieDomain'))
->set('dialog.readmoreLink', $form_state
->getValue('readmoreLink'))
->save();
parent::submitForm($form, $form_state);
}
}