You are here

function cookies_menu_links_discovered_alter in COOKiES Consent Management 1.0.x

Implements hook_menu_links_discovered_alter().

File

./cookies.module, line 70
Contains cookies.module.

Code

function cookies_menu_links_discovered_alter(&$links) {

  /*
   * Define the "Cookie settings" menu item in Tools.
   * Dynamic equivalent of links.menu.yml entry, but we need to set the URL
   * dynamically because the dialog open fragment can be configured in COOKiES
   * settings.
   *
   * cookies.open_cookie_consent_dialog:
   * title: "Cookie settings"
   * description: "Open the cookie consent dialog."
   * url: "internal:<DYNAMIC:#editCookieSettings>"
   * menu_name: tools
   * options:
   *   attributes:
   *     class:
   *       - cookies-open-cookie-consent-dialog
   */
  $open_settings_hash = \Drupal::config('cookies.config')
    ->get('open_settings_hash');
  if (!empty($open_settings_hash)) {
    $links['cookies.open_cookie_consent_dialog'] = [
      'title' => new TranslatableMarkup("Cookie settings"),
      'description' => new TranslatableMarkup("Open the cookie consent dialog."),
      'url' => "internal:#" . htmlspecialchars($open_settings_hash, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'),
      'menu_name' => 'tools',
      'provider' => 'cookies',
      'options' => [
        'attributes' => [
          'class' => 'cookies-open-cookie-consent-dialog',
        ],
      ],
    ];
  }
}