Commit 67a8cdff authored by Sven Berg Ryen's avatar Sven Berg Ryen Committed by Sven Berg Ryen
Browse files

Issue #2985390 by Anybody, svenryen, jo.st, flefle, MrPaulDriver, upunkt,...

Issue #2985390 by Anybody, svenryen, jo.st, flefle, MrPaulDriver, upunkt, leymannx, bramvandenbulcke, gabrimonfa, Grayle, portulaca, anderz, RobbM: [1.x] Option to place Withdraw Button anywhere on site (e.g. in block)
parent 2015c64b
Loading
Loading
Loading
Loading
+1 −0
Changes for eu_cookie_compliance.admin.inc: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -448,6 +448,7 @@ function eu_cookie_compliance_admin_form(array $form, array $form_state) {
    '#type' => 'checkbox',
    '#title' => t('Enable floating privacy settings tab and withdraw consent banner'),
    '#default_value' => isset($popup_settings['withdraw_enabled']) ? $popup_settings['withdraw_enabled'] : '',
    '#description' => t('Adds a floating privacy settings tab and withdraw consent banner. This option also provides a "Cookie settings" button block and menu item suggestion in the "Navigation" menu.'),
  );

  $form['withdraw_consent']['eu_cookie_compliance']['withdraw_button_on_info_popup'] = array(
+86 −0
Changes for eu_cookie_compliance.module: 86 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -77,6 +77,30 @@ function eu_cookie_compliance_menu() {
      'access arguments' => array('display EU Cookie Compliance popup'),
    );
  }
  if (eu_cookie_compliance_get_settings('withdraw_enabled')) {
    // Cookie settings menu item suggestion which can be found in the
    // 'navigation' menu.
    // Toggles the withdraw banner using JavaScript. Because Drupal 7 doesn't
    // allow menu items without link and callback, we use a dummy redirect to
    // the privacy policy instead as fragment fallback.
    $items['#editCookieSettings'] = array(
      'title' => 'Cookie settings',
      'description' => 'Toggle the cookie consent settings tray.',
      'page callback' => 'eu_cookie_compliance_privacy_policy_redirect',
      'type' => MENU_SUGGESTED_ITEM,
      'access arguments' => array('display EU Cookie Compliance popup'),
      'menu_name' => 'navigation',
      'options' => array(
        'external' => TRUE,
        // Pseudo.
        'fragment' => 'editCookieSettings',
        'attributes' => array(
          'class' => 'eu-cookie-compliance-toggle-withdraw-banner',
          'rel' => 'nofollow',
        ),
      ),
    );
  }

  return $items;
}
@@ -869,6 +893,50 @@ function eu_cookie_compliance_library_alter(&$libraries, $module) {
  $libraries['jquery.cookie']['version'] = '1.4.1';
}

/**
 * Implements hook_block_info().
 */
function eu_cookie_compliance_block_info() {
  // Cookie Settings button block:
  $blocks['cookie_settings_button'] = array(
    'info' => t('EU Cookie Compliance: "Cookie settings" Button'),
    'cache' => DRUPAL_CACHE_GLOBAL,
  );
  return $blocks;
}

/**
 * Implements hook_block_view().
 */
function eu_cookie_compliance_block_view($delta = '') {
  $block = array();
  switch ($delta) {
    // Cookie Settings button block:
    case 'cookie_settings_button':
      $block['subject'] = t('Cookie settings');
      if (eu_cookie_compliance_get_settings('withdraw_enabled')) {
        $block['content'] = array(
          '#type' => 'link',
          '#title' => t('Cookie settings'),
          '#href' => '#',
          '#attributes' => array(
            'class' => 'button eu-cookie-compliance-toggle-withdraw-banner',
            'onclick' => 'Drupal.eu_cookie_compliance.toggleWithdrawBanner(); return false;',
            'rel' => 'nofollow',
          ),
        );
      }
      else {
        $block['content'] = t('This block requires the "@withdraw_enabled_setting_name" to be enabled in !eu_cookie_compliance_settings.', array(
          '@withdraw_enabled_setting_name' => t('Enable floating privacy settings tab and withdraw consent banner'),
          '!eu_cookie_compliance_settings' => l(t('EU Cookie Compliance settings'), 'admin/config/system/eu-cookie-compliance'),
        ));
      }
      break;
  }
  return $block;
}

/**
 * Splits a return delimited text string into an array.
 *
@@ -961,6 +1029,24 @@ function eu_cookie_compliance_store_consent($type) {
  drupal_exit();
}

/**
 * Menu callback for the 'Cookie settings' menu item suggestion.
 *
 * Because that menu item is a JavaScript function which toggles
 * Drupal.eu_cookie_compliance.toggleWithdrawBanner(); but Drupal 7 menu items
 * require a callback, this is mainly a dummy placeholder.
 *
 * To give it useful functionality, we redirect to the privacy policy page if
 * the placeholder link is accessed.
 */
function eu_cookie_compliance_privacy_policy_redirect() {
  $popup_link = url(token_replace(eu_cookie_compliance_get_settings('popup_link')));
  if (!empty($popup_link)) {
    return drupal_goto($popup_link);
  }
  return drupal_goto('<front>');
}

/**
 * Convert uri to relative path.
 *
+7 −0
Changes for js/eu_cookie_compliance.js: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -47,6 +47,13 @@
          Drupal.eu_cookie_compliance.execute();
        }
      }).addClass('eu-cookie-compliance-status-' + Drupal.eu_cookie_compliance.getCurrentStatus());

      // Toggle withdraw banner on links with toggle class:
      $('a.eu-cookie-compliance-toggle-withdraw-banner', context).click(function(e) {
        e.preventDefault();
        Drupal.eu_cookie_compliance.toggleWithdrawBanner();
        return false;
      });
    }
  };