View source
<?php
namespace Drupal\tacjs\Form\Steps;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
class EditTexts extends FormBase {
public function getFormId() {
return 'tacjs_edit_texts';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$config = \Drupal::getContainer()
->get('config.factory')
->getEditable('tacjs.settings');
$texts = [
[
'id' => 'adblock',
'msg' => 'Hello! This site is transparent and lets you chose the 3rd party services you want to allow.',
],
[
'id' => 'adblock_call',
'msg' => 'Please disable your adblocker to start customizing.',
],
[
'id' => 'reload',
'msg' => 'Refresh the page',
],
[
'id' => 'alertBigScroll',
'msg' => 'By continuing to scroll,',
],
[
'id' => 'alertBigClick',
'msg' => 'If you continue to browse this website,',
],
[
'id' => 'alertBig',
'msg' => 'you are allowing all third-party services',
],
[
'id' => 'alertBigPrivacy',
'msg' => 'This site uses cookies and gives you control over what you want to activate',
],
[
'id' => 'alertSmall',
'msg' => 'Manage services',
],
[
'id' => 'personalize',
'msg' => 'Personalize',
],
[
'id' => 'acceptAll',
'msg' => 'OK, accept all',
],
[
'id' => 'close',
'msg' => 'Close',
],
[
'id' => 'privacyUrl',
'msg' => 'Privacy policy',
],
[
'id' => 'all',
'msg' => 'Preference for all services',
],
[
'id' => 'info',
'msg' => 'Protecting your privacy',
],
[
'id' => 'disclaimer',
'msg' => 'By allowing these third party services, you accept their cookies and the use of tracking technologies necessary for their proper functioning.',
],
[
'id' => 'allow',
'msg' => 'Allow',
],
[
'id' => 'deny',
'msg' => 'Deny',
],
[
'id' => 'noCookie',
'msg' => 'This service does not use cookie.',
],
[
'id' => 'useCookie',
'msg' => 'This service can install',
],
[
'id' => 'useCookieCurrent',
'msg' => 'This service has installed',
],
[
'id' => 'useNoCookie',
'msg' => 'This service has not installed any cookie.',
],
[
'id' => 'more',
'msg' => 'Read more',
],
[
'id' => 'source',
'msg' => 'View the official website',
],
[
'id' => 'credit',
'msg' => 'Cookies manager by tarteaucitron.js',
],
[
'id' => 'toggleInfoBox',
'msg' => 'Show/hide informations about cookie storage',
],
[
'id' => 'title',
'msg' => 'Cookies management panel',
],
[
'id' => 'cookieDetail',
'msg' => 'Cookie detail for',
],
[
'id' => 'ourSite',
'msg' => 'on our site',
],
[
'id' => 'newWindow',
'msg' => '(new window)',
],
[
'id' => 'allowAll',
'msg' => 'Allow all cookies',
],
[
'id' => 'denyAll',
'msg' => 'Deny all cookies',
],
[
'id' => 'fallback',
'msg' => 'is disabled.',
],
[
'id' => 'ads_title',
'msg' => 'Advertising network',
],
[
'id' => 'ads_details',
'msg' => 'Ad networks can generate revenue by selling advertising space on the site.',
],
[
'id' => 'analytic_title',
'msg' => 'Audience measurement',
],
[
'id' => 'analytic_details',
'msg' => 'The audience measurement services used to generate useful statistics attendance to improve the site.',
],
[
'id' => 'social_title',
'msg' => 'Social networks',
],
[
'id' => 'social_details',
'msg' => 'Social networks can improve the usability of the site and help to promote it via the shares.',
],
[
'id' => 'video_title',
'msg' => 'Videos',
],
[
'id' => 'video_details',
'msg' => 'Video sharing services help to add rich media on the site and increase its visibility.',
],
[
'id' => 'comment_title',
'msg' => 'Comments',
],
[
'id' => 'comment_details',
'msg' => 'Comments managers facilitate the filing of comments and fight against spam.',
],
[
'id' => 'support_title',
'msg' => 'Support',
],
[
'id' => 'support_details',
'msg' => 'Support services allow you to get in touch with the site team and help to improve it.',
],
[
'id' => 'api_title',
'msg' => 'APIs',
],
[
'id' => 'api_details',
'msg' => 'APIs are used to load scripts, geolocation, search engines, translations, ...',
],
[
'id' => 'other_title',
'msg' => 'Other',
],
[
'id' => 'other_details',
'msg' => 'Services to display web content.',
],
];
$form['texts'] = [
'#prefix' => '<p>' . t('Enter the text that will be presented to your website users. The same text is used in both the cookie declaration and the consent dialog.') . '<br />' . t('Translate the text on the <a href=":translate">User interface translation</a> page.', [
':translate' => Url::fromRoute('locale.translate_page')
->toString(),
]) . '</p>',
'#type' => 'table',
'#header' => [
'original' => $this
->t('Original'),
'destination' => $this
->t('Destination'),
],
'#rows' => [],
];
for ($i = 0; $i < count($texts); $i++) {
$form['texts'][$i] = [
'original' => [
'#type' => 'inline_template',
'#template' => '<strong>{{ msg }}</strong>',
'#context' => [
'msg' => $texts[$i]['msg'],
],
],
'destination' => [
'#type' => 'textarea',
'#title' => t('Destination'),
'#title_display' => 'invisible',
'#default_value' => $config
->get('texts.' . $texts[$i]['id']),
],
];
}
$form['submit'] = [
'#type' => 'submit',
'#value' => t('Save'),
];
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = \Drupal::getContainer()
->get('config.factory')
->getEditable('tacjs.settings');
$texts = [
'adblock',
'adblock_call',
'reload',
'alertBigScroll',
'alertBigClick',
'alertBig',
'alertBigPrivacy',
'alertSmall',
'personalize',
'acceptAll',
'close',
'privacyUrl',
'all',
'info',
'disclaimer',
'allow',
'deny',
'noCookie',
'useCookie',
'useCookieCurrent',
'useNoCookie',
'more',
'source',
'credit',
'toggleInfoBox',
'title',
'cookieDetail',
'ourSite',
'newWindow',
'allowAll',
'denyAll',
'fallback',
'ads_title',
'ads_details',
'analytic_title',
'analytic_details',
'social_title',
'social_details',
'video_title',
'video_details',
'comment_title',
'comment_details',
'support_title',
'support_details',
'api_title',
'api_details',
'other_title',
'other_details',
];
for ($i = 0; $i < count($texts); $i++) {
$config
->set('texts.' . $texts[$i], $form_state
->getValue('texts')[$i]['destination']);
}
$config
->save();
}
}