- Issue created by @aleix
- Merge request !28Use of Attribute in templates to make it easier for consent managers → (Open) created by aleix
- 🇪🇸Spain aleix
!27 MR was using bad branch dest...
!28 is the good one , with these changes, minor preprocess needs to be done to make it work with klaro. something like:/** * Implements hook_preprocess_HOOK() for dfp templates. */ function dfp_klaro_preprocess_dfp_js_head_top(&$variables) { /** @var \Drupal\klaro\Utility\KlaroHelper $helper */ $helper = \Drupal::service('klaro.helper'); $service = $helper->matchKlaroApp($variables["google_tag_services_url"]); if ($service) { $variables['gads_dataset'] = [ 'type' => 'text/javascript', 'name' => 'dfp_admanager', 'src' => $variables["google_tag_services_url"], ]; } } /** * Implements hook_preprocess_HOOK() for dfp templates. */ function dfp_klaro_preprocess_dfp_short_tag(&$variables) { /** @var \Drupal\klaro\Utility\KlaroHelper $helper */ $helper = \Drupal::service('klaro.helper'); $service = $helper->matchKlaroApp(TagInterface::GOOGLE_TAG_SERVICES_URL); if ($service) { $variables['image_attributes'] = $helper->rewriteAttributes($variables['image_attributes'], $service->id()); } } /** * Implements hook_preprocess_HOOK() for dfp templates. */ function dfp_klaro_preprocess_dfp_tag(&$variables) { _dfp_klaro_preprocess_dfp($variables); } /** * Implements hook_preprocess_HOOK() for dfp templates. */ function dfp_klaro_preprocess_dfp_js_head_bottom(&$variables) { _dfp_klaro_preprocess_dfp($variables); } /** * Implements hook_preprocess_HOOK() for dfp templates. */ function dfp_klaro_preprocess_dfp_slot_definition_js(&$variables) { _dfp_klaro_preprocess_dfp($variables); } /** * Adds the klaro attributes to each script preprocessed by dfp. */ function _dfp_klaro_preprocess_dfp(&$variables) { /** @var \Drupal\klaro\Utility\KlaroHelper $helper */ $helper = \Drupal::service('klaro.helper'); $service = $helper->matchKlaroApp(TagInterface::GOOGLE_TAG_SERVICES_URL); if ($service) { $variables['script_attributes'] = $helper->rewriteAttributes($variables['script_attributes'], $service->id()); } }