' . t('About') . ''; $output .= '
' . t('helpers for progressive decoupling') . '
'; return $output; default: } } /** * Implements hook_page_attachments(). * @param array $attachments */ function materio_decoupled_page_attachments(array &$attachments) { $current_path = \Drupal::service('path.current')->getPath(); $current_language = \Drupal::languageManager()->getCurrentLanguage()->getId(); $is_front = \Drupal::service('path.matcher')->isFrontPage(); $entity_type = null; $entity_bundle = null; $entity_id = null; foreach (['node', 'taxonomy_term'] as $type) { $entity = \Drupal::routeMatch()->getParameter($type); if($entity){ $entity_type = $type; $entity_bundle = $entity->bundle(); $entity_id = $entity->id(); $entity_uuid = $entity->uuid(); break; } } $js_str = "var drupalDecoupled = {\n sys_path:'".$current_path."',\n is_front:".($is_front ? 'true':'false').",\n lang_code:'".$current_language."',\n entity_type:'".$entity_type."',\n entity_bundle:'".$entity_bundle."',\n entity_id:'".$entity_id."',\n entity_uuid:'".$entity_uuid."',\n };"; $attachments['#attached']['html_head'][] = [ [ '#type' => 'html_tag', '#tag' => 'script', '#value' => $js_str, '#weight' => -999, '#group' => 'decoupled' ], // A key, to make it possible to recognize this HTML element when altering. 'decoupled', ]; }