Loading config/install/eu_cookie_compliance.settings.yml +4 −0 Original line number Diff line number Diff line Loading @@ -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 Loading config/schema/eu_cookie_compliance.schema.yml +13 −0 Original line number Diff line number Diff line Loading @@ -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' Loading eu_cookie_compliance.module +11 −0 Original line number Diff line number Diff line Loading @@ -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), Loading @@ -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) { Loading @@ -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%', Loading js/eu_cookie_compliance.js +7 −1 Original line number Diff line number Diff line Loading @@ -59,8 +59,14 @@ Drupal.eu_cookie_compliance.changeStatus(next_status); }); // 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); if (popup_hide_agreed) { Loading src/Form/EuCookieComplianceConfigForm.php +41 −0 Original line number Diff line number Diff line Loading @@ -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'), Loading Loading @@ -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')) Loading @@ -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')) Loading Loading
config/install/eu_cookie_compliance.settings.yml +4 −0 Original line number Diff line number Diff line Loading @@ -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 Loading
config/schema/eu_cookie_compliance.schema.yml +13 −0 Original line number Diff line number Diff line Loading @@ -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' Loading
eu_cookie_compliance.module +11 −0 Original line number Diff line number Diff line Loading @@ -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), Loading @@ -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) { Loading @@ -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%', Loading
js/eu_cookie_compliance.js +7 −1 Original line number Diff line number Diff line Loading @@ -59,8 +59,14 @@ Drupal.eu_cookie_compliance.changeStatus(next_status); }); // 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); if (popup_hide_agreed) { Loading
src/Form/EuCookieComplianceConfigForm.php +41 −0 Original line number Diff line number Diff line Loading @@ -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'), Loading Loading @@ -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')) Loading @@ -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')) Loading