diff --git a/README.md b/README.md index 961b684..8d9a5d3 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,8 @@ This module provides a configurable consent popup block. All he texts are configurable. When the consent is declined the configured text and a link to a new page is showed. -If consent is given a global cookie is stored on the site (also configured in the block). +If consent is given a global cookie is stored on the site +(also configured in the block). There are also some design configurations that you can change: - Elements to be blured when the popup is openend. diff --git a/README.txt b/README.txt index 748a623..94c4132 100644 --- a/README.txt +++ b/README.txt @@ -12,7 +12,8 @@ This module provides a configurable consent popup block. All he texts are configurable. When the consent is declined the configured text and a link to a new page is showed. -If consent is given a global cookie is stored on the site (also configured in the block). +If consent is given a global cookie is stored on the site +(also configured in the block). There are also some design configurations that you can change: - Elements to be blured when the popup is openend diff --git a/consent_popup.module b/consent_popup.module index 467a53d..4b07e0f 100644 --- a/consent_popup.module +++ b/consent_popup.module @@ -3,12 +3,11 @@ /** * @file * This module provides a consent popup block. - * */ - use Drupal\Core\Routing\RouteMatchInterface; +use Drupal\Core\Routing\RouteMatchInterface; - /** +/** * Implements hook_help(). */ function consent_popup_help($route_name, RouteMatchInterface $route_match) { @@ -38,12 +37,12 @@ function consent_popup_help($route_name, RouteMatchInterface $route_match) { * Implements hook_theme(). */ function consent_popup_theme() { - return [ - 'consent_popup' => [ - 'variables' => [ - 'items' => NULL, - ], - 'template' => 'consent-popup' - ] - ]; -} \ No newline at end of file + return [ + 'consent_popup' => [ + 'variables' => [ + 'items' => NULL, + ], + 'template' => 'consent-popup', + ], + ]; +} diff --git a/js/consent-popup.js b/js/consent-popup.js index 19b0f3a..1621c93 100644 --- a/js/consent-popup.js +++ b/js/consent-popup.js @@ -43,7 +43,8 @@ const cArr = cDecoded.split("; "); let res; cArr.forEach((val) => { - if (val.indexOf(name) === 0) res = val.substring(name.length); + if (val.indexOf(name) === 0) { res = val.substring(name.length); + } }); return res; } diff --git a/src/Plugin/Block/ConsentPopupBlock.php b/src/Plugin/Block/ConsentPopupBlock.php index a0a2170..3cc8e28 100644 --- a/src/Plugin/Block/ConsentPopupBlock.php +++ b/src/Plugin/Block/ConsentPopupBlock.php @@ -1,6 +1,7 @@ <?php namespace Drupal\consent_popup\Plugin\Block; + use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Block\BlockBase; @@ -34,84 +35,84 @@ class ConsentPopupBlock extends BlockBase { $form[$key]['text'] = [ '#type' => 'textarea', '#title' => $this->t('Popup Text'), - '#default_value' => isset($config[$key]['text']) ? - $config[$key]['text'] : $this->t("Are you an adult?"), - '#required' => true + '#default_value' => isset($config[$key]['text']) ? + $config[$key]['text'] : $this->t("Are you an adult?"), + '#required' => TRUE, ]; $form[$key]['text_decline'] = [ '#type' => 'textarea', '#title' => $this->t('Declined Text'), - '#default_value' => isset($config[$key]['text_decline']) ? - $config[$key]['text_decline'] : - $this->t("You can't access this page"), - '#required' => true + '#default_value' => isset($config[$key]['text_decline']) ? + $config[$key]['text_decline'] : + $this->t("You can't access this page"), + '#required' => TRUE, ]; $form[$key]['accept'] = [ '#type' => 'textfield', '#title' => $this->t('Accept button text'), - '#default_value' => isset($config[$key]['accept']) ? $config[$key]['accept'] : $this->t('Yes'), + '#default_value' => isset($config[$key]['accept']) ? $config[$key]['accept'] : $this->t('Yes'), '#description' => $this->t('Default value: Yes'), - '#required' => true + '#required' => TRUE, ]; $form[$key]['decline'] = [ '#type' => 'textfield', '#title' => $this->t('Decline button text'), - '#default_value' => isset($config[$key]['decline']) ? $config[$key]['decline'] : $this->t('No'), + '#default_value' => isset($config[$key]['decline']) ? $config[$key]['decline'] : $this->t('No'), '#description' => $this->t('Default value: No'), - '#required' => true + '#required' => TRUE, ]; } - $form['decline_link'] =[ + $form['decline_link'] = [ '#type' => 'fieldset', '#title' => $this->t('Decline url options'), - '#description' => $this->t('Options for the link to show when declined') + '#description' => $this->t('Options for the link to show when declined'), ]; $form['decline_link']['decline_url'] = [ '#type' => 'textfield', '#title' => $this->t('Link url if declined'), - '#default_value' => isset($config['decline_link']['decline_url']) ? $config['decline_link']['decline_url'] : '/', - '#description' => $this->t("Please use a relative url. Default value '/' (home) "), - '#required' => true + '#default_value' => isset($config['decline_link']['decline_url']) ? $config['decline_link']['decline_url'] : '/', + '#description' => $this->t("Please use a relative url. Default value '/' (home)"), + '#required' => TRUE, ]; $form['decline_link']['decline_url_text'] = [ '#type' => 'textfield', '#title' => $this->t('Text for url if declined'), - '#default_value' => isset($config['decline_link']['decline_url_text']) ? $config['decline_link']['decline_url_text'] : $this->t('Keep browsing our site'), + '#default_value' => isset($config['decline_link']['decline_url_text']) ? $config['decline_link']['decline_url_text'] : $this->t('Keep browsing our site'), '#description' => $this->t("Link text. Default value 'Keep browsing our site'"), - '#required' => true + '#required' => TRUE, ]; - $form['cookie'] =[ + $form['cookie'] = [ '#type' => 'fieldset', '#title' => $this->t('Cookie Info'), - '#description' => $this->t('Options for the link to show when declined') + '#description' => $this->t('Options for the link to show when declined'), ]; $form['cookie']['cookie_name'] = [ '#type' => 'textfield', '#title' => $this->t('Cookie Name'), - '#default_value' => isset($config['cookie']['cookie_name']) ? $config['cookie']['cookie_name'] : 'consent_popup', + '#default_value' => isset($config['cookie']['cookie_name']) ? $config['cookie']['cookie_name'] : 'consent_popup', '#description' => $this->t("Name of the cookie (defaults to consent_popup)"), - '#required' => true + '#required' => TRUE, ]; $form['cookie']['cookie_life'] = [ '#type' => 'number', '#title' => $this->t('Cookie life time'), - '#default_value' => isset($config['cookie']['cookie_life']) ? $config['cookie']['cookie_life'] : 7, - '#description' => $this->t("how many days until the cookie is deleted (defaults to 7)") + '#default_value' => isset($config['cookie']['cookie_life']) ? $config['cookie']['cookie_life'] : 7, + '#description' => $this->t("how many days until the cookie is deleted (defaults to 7)"), ]; - $form['design'] =[ + $form['design'] = [ '#type' => 'fieldset', '#title' => $this->t('Cookie Info'), - '#description' => $this->t('Options for the link to show when declined') + '#description' => $this->t('Options for the link to show when declined'), ]; - $form['design']['color'] = array( + $form['design']['color'] = [ '#type' => 'color', '#title' => $this ->t('Background Color'), '#default_value' => isset($config['design']['color']) ? $config['design']['color'] : '#000000', - ); + ]; $form['design']['color_opacity'] = [ '#type' => 'select', - '#title' => t('Background Opacity'), + '#title' => $this->t('Background Opacity'), '#description' => $this->t('Chose the filter opacity'), '#options' => range(0, 1, 0.1), '#default_value' => isset($config['design']['color_opacity']) ? $config['design']['color_opacity'] : '8', @@ -119,12 +120,11 @@ class ConsentPopupBlock extends BlockBase { $form['design']['blur'] = [ '#type' => 'textfield', '#title' => $this->t('Elements to blur'), - '#default_value' => isset($config['design']['blur']) ? $config['design']['blur'] : '', - '#description' => $this->t("Use css selectors to chose elements to blur separated with , ") + '#default_value' => isset($config['design']['blur']) ? $config['design']['blur'] : '', + '#description' => $this->t("Use css selectors to chose elements to blur separated with ,"), ]; return $form; } - /** * {@inheritdoc} @@ -145,20 +145,20 @@ class ConsentPopupBlock extends BlockBase { $config = $this->getConfiguration(); list($r, $g, $b) = sscanf($config['design']['color'], "#%02x%02x%02x"); $opacity = $config['design']['color_opacity'] / 10; - $color = "rgb(".$r." ".$g." ".$b." / ".$opacity.")"; - $blurElements = explode(',',$config['design']['blur']); - $build = [ + $color = "rgb(" . $r . " " . $g . " " . $b . " / " . $opacity . ")"; + $blurElements = explode(',', $config['design']['blur']); + $build = [ '#theme' => 'consent_popup', '#items' => [ 'text' => $config[$languageKey]['text'], 'accept' => $config[$languageKey]['accept'], 'decline' => $config[$languageKey]['decline'], 'url' => $config['decline_link']['decline_url'], - 'url_text' => $config['decline_link']['decline_url_text'] + 'url_text' => $config['decline_link']['decline_url_text'], ], - '#attached' =>[ + '#attached' => [ 'library' => [ - 'consent_popup/consent_popup' + 'consent_popup/consent_popup', ], 'drupalSettings' => [ 'consent_popup' => [ @@ -166,11 +166,12 @@ class ConsentPopupBlock extends BlockBase { 'cookie_name' => $config['cookie']['cookie_name'], 'text_decline' => $config[$languageKey]['text_decline'], 'bg_color' => $color, - 'to_blur' => $blurElements - ] - ] - ] + 'to_blur' => $blurElements, + ], + ], + ], ]; return $build; } + } diff --git a/templates/consent-popup.html.twig b/templates/consent-popup.html.twig index 0ddd863..998a406 100644 --- a/templates/consent-popup.html.twig +++ b/templates/consent-popup.html.twig @@ -5,4 +5,4 @@ <button class="decline">{{ items.decline }}</button> </div> <a class="visually-hidden" href="{{ items.url }}">{{ items.url_text }}</a> -</div> \ No newline at end of file +</div>