summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLNakamura2018-02-25 13:21:42 (GMT)
committerSven Berg Ryen2018-02-25 13:21:42 (GMT)
commite34aaf99e4cc7cf6917f162ff5691aca617c860f (patch)
tree5ba1b07141af4172a1c30ad1ca01be6e3c56ff12
parentd3ea1df8494695620ef0daeea20956bdd28b669b (diff)
Issue #2921182 by LNakamura, svenryen: Provide alternate popup message text for mobile devices
-rw-r--r--config/install/eu_cookie_compliance.settings.yml4
-rw-r--r--config/schema/eu_cookie_compliance.schema.yml13
-rw-r--r--eu_cookie_compliance.module11
-rw-r--r--js/eu_cookie_compliance.js8
-rw-r--r--src/Form/EuCookieComplianceConfigForm.php41
5 files changed, 76 insertions, 1 deletions
diff --git a/config/install/eu_cookie_compliance.settings.yml b/config/install/eu_cookie_compliance.settings.yml
index 503304e..f4f1d25 100644
--- a/config/install/eu_cookie_compliance.settings.yml
+++ b/config/install/eu_cookie_compliance.settings.yml
@@ -26,6 +26,10 @@ popup_hide_button_message: 'Hide'
popup_info:
value: '<h2>We use cookies on this site to enhance your user experience</h2><p>By clicking any link on this page you are giving your consent for us to set cookies.</p>'
format: 'restricted_html'
+mobile_popup_info:
+ value: '<h2>We use cookies on this site to enhance your user experience</h2><p>By tapping any link on this page you are giving your consent for us to set cookies.</p>'
+ format: 'restricted_html'
+mobile_breakpoint: 768
popup_link: ''
popup_link_new_window: true
popup_position: false
diff --git a/config/schema/eu_cookie_compliance.schema.yml b/config/schema/eu_cookie_compliance.schema.yml
index 0098b0e..891aea3 100644
--- a/config/schema/eu_cookie_compliance.schema.yml
+++ b/config/schema/eu_cookie_compliance.schema.yml
@@ -38,6 +38,19 @@ eu_cookie_compliance.settings:
format:
type: string
label: 'Popup message - Format'
+ mobile_popup_info:
+ type: mapping
+ label: 'Mobile popup message - requests consent'
+ mapping:
+ value:
+ type: text
+ label: 'Mobile popup message - Value'
+ format:
+ type: string
+ label: 'Mobile popup message - Format'
+ mobile_breakpoint:
+ type: integer
+ label: 'Mobile breakpoint'
popup_agreed_enabled:
type: boolean
label: 'Enable thank you message'
diff --git a/eu_cookie_compliance.module b/eu_cookie_compliance.module
index 620cf11..cd5d630 100644
--- a/eu_cookie_compliance.module
+++ b/eu_cookie_compliance.module
@@ -140,6 +140,13 @@ function eu_cookie_compliance_page_attachments(&$attachments) {
'#agree_button' => $config->get('popup_agree_button_message'),
'#disagree_button' => $config->get('popup_disagree_button_message'),
);
+ $mobile_popup_text_info = str_replace(array("\r", "\n"), '', $config->get('mobile_popup_info.value'));
+ $mobile_html_info = array(
+ '#theme' => 'eu_cookie_compliance_popup_info',
+ '#message' => check_markup($mobile_popup_text_info, $config->get('popup_info.format'), FALSE),
+ '#agree_button' => $config->get('popup_agree_button_message'),
+ '#disagree_button' => $config->get('popup_disagree_button_message'),
+ );
$html_agreed = array(
'#theme' => 'eu_cookie_compliance_popup_agreed',
'#message' => check_markup($popup_text_agreed, $config->get('popup_agreed.format'), FALSE),
@@ -160,6 +167,7 @@ function eu_cookie_compliance_page_attachments(&$attachments) {
}
$html_info = trim(\Drupal::service('renderer')->renderRoot($html_info)->__toString());
+ $mobile_html_info = trim(\Drupal::service('renderer')->renderRoot($mobile_html_info)->__toString());
$html_agreed = trim(\Drupal::service('renderer')->renderRoot($html_agreed)->__toString());
if ($was_debugging) {
@@ -183,6 +191,9 @@ function eu_cookie_compliance_page_attachments(&$attachments) {
'popup_clicking_confirmation' => $config->get('popup_clicking_confirmation'),
'popup_scrolling_confirmation' => $config->get('popup_scrolling_confirmation'),
'popup_html_info' => $config->get('popup_enabled') ? $html_info : FALSE,
+ 'use_mobile_message' => !empty($config->get('use_mobile_message')) ? $config->get('use_mobile_message') : FALSE,
+ 'mobile_popup_html_info' => $config->get('popup_enabled') ? $mobile_html_info : FALSE,
+ 'mobile_breakpoint' => !empty($config->get('mobile_breakpoint')) ? $config->get('mobile_breakpoint') : '768',
'popup_html_agreed' => $config->get('popup_agreed_enabled') ? $html_agreed : FALSE,
'popup_height' => !empty($config->get('popup_height')) ? $config->get('popup_height') : 'auto',
'popup_width' => !empty($config->get('popup_width')) ? $config->get('popup_width') : '100%',
diff --git a/js/eu_cookie_compliance.js b/js/eu_cookie_compliance.js
index a7f66ce..00c6099 100644
--- a/js/eu_cookie_compliance.js
+++ b/js/eu_cookie_compliance.js
@@ -59,7 +59,13 @@
Drupal.eu_cookie_compliance.changeStatus(next_status);
});
- Drupal.eu_cookie_compliance.createPopup(settings.popup_html_info);
+ // Detect mobile here and use mobile_popup_html_info, if we have a mobile device.
+ if (window.matchMedia('(max-width: ' + settings.mobile_breakpoint + 'px)').matches && settings.use_mobile_message) {
+ Drupal.eu_cookie_compliance.createPopup(settings.mobile_popup_html_info);
+ }
+ else {
+ Drupal.eu_cookie_compliance.createPopup(settings.popup_html_info);
+ }
}
else if (status === 1) {
Drupal.eu_cookie_compliance.createPopup(settings.popup_html_agreed);
diff --git a/src/Form/EuCookieComplianceConfigForm.php b/src/Form/EuCookieComplianceConfigForm.php
index 43449bc..cac9c55 100644
--- a/src/Form/EuCookieComplianceConfigForm.php
+++ b/src/Form/EuCookieComplianceConfigForm.php
@@ -117,6 +117,40 @@ class EuCookieComplianceConfigForm extends ConfigFormBase {
'#format' => !empty($config->get('popup_info.format')) ? $config->get('popup_info.format') : $default_filter_format,
);
+ $form['popup_message']['use_mobile_message'] = array(
+ '#type' => 'checkbox',
+ '#title' => $this->t('Use a different message for mobile phones'),
+ '#default_value' => ($config->get('mobile_popup_info.value') != ''),
+ );
+
+ $form['popup_message']['container'] = array(
+ '#type' => 'container',
+ '#states' => array('visible' => array('input[name="use_mobile_message"]' => array('checked' => true))),
+ );
+
+ $form['popup_message']['container']['mobile_popup_info'] = array(
+ '#type' => 'text_format',
+ '#title' => $this->t('Mobile popup message - requests consent'),
+ '#default_value' => $config->get('mobile_popup_info.value'),
+ '#required' => FALSE,
+ '#format' => !empty($config->get('mobile_popup_info.format')) ? $config->get('mobile_popup_info.format') : $default_filter_format,
+ );
+
+ $form['popup_message']['mobile_breakpoint'] = array(
+ '#type' => 'number',
+ '#title' => $this->t('Mobile breakpoint'),
+ '#default_value' => !empty($config->get('mobile_breakpoint')) ? $config->get('mobile_breakpoint') : '768',
+ '#field_suffix' => ' ' . $this->t('pixels'),
+ '#size' => 4,
+ '#maxlength' => 4,
+ '#required' => FALSE,
+ '#description' => $this->t('The mobile message will be used when the window width is below or equal to the given value.'),
+ '#states' => array(
+ "visible" => array(
+ "input[name='use_mobile_message']" => array("checked" => TRUE)),
+ ),
+ );
+
$form['popup_message']['popup_agree_button_message'] = array(
'#type' => 'textfield',
'#title' => $this->t('Agree button label'),
@@ -348,6 +382,10 @@ class EuCookieComplianceConfigForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
+ if (trim($form_state->getValue('mobile_popup_info')['value']) == '') {
+ $form_state->setValue('use_mobile_message', FALSE);
+ }
+
$this->config('eu_cookie_compliance.settings')
->set('domain', $form_state->getValue('domain'))
->set('popup_enabled', $form_state->getValue('popup_enabled'))
@@ -357,6 +395,9 @@ class EuCookieComplianceConfigForm extends ConfigFormBase {
->set('popup_agree_button_message', $form_state->getValue('popup_agree_button_message'))
->set('popup_disagree_button_message', $form_state->getValue('popup_disagree_button_message'))
->set('popup_info', $form_state->getValue('popup_info'))
+ ->set('use_mobile_message', $form_state->getValue('use_mobile_message'))
+ ->set('mobile_popup_info', $form_state->getValue('use_mobile_message') ? $form_state->getValue('mobile_popup_info') : '')
+ ->set('mobile_breakpoint', $form_state->getValue('mobile_breakpoint'))
->set('popup_agreed_enabled', $form_state->getValue('popup_agreed_enabled'))
->set('popup_hide_agreed', $form_state->getValue('popup_hide_agreed'))
->set('popup_find_more_button_message', $form_state->getValue('popup_find_more_button_message'))