system_page_attachments(array &$page)
Implements hook_page_attachments().
See also
template_preprocess_maintenance_page()
\Drupal\Core\EventSubscriber\ActiveLinkResponseFilter
File
- core/modules/system/system.module, line 547
- Configuration system that lets administrators modify the workings of the site.
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | function system_page_attachments( array & $page ) { // Ensure the same CSS is loaded in template_preprocess_maintenance_page(). $page [ '#attached' ][ 'library' ][] = 'system/base' ; if (\Drupal::service( 'router.admin_context' )->isAdminRoute()) { $page [ '#attached' ][ 'library' ][] = 'system/admin' ; } // Attach libraries used by this theme. $active_theme = \Drupal::theme()->getActiveTheme(); foreach ( $active_theme ->getLibraries() as $library ) { $page [ '#attached' ][ 'library' ][] = $library ; } // Attach favicon. if (theme_get_setting( 'features.favicon' )) { $favicon = theme_get_setting( 'favicon.url' ); $type = theme_get_setting( 'favicon.mimetype' ); $page [ '#attached' ][ 'html_head_link' ][][] = array ( 'rel' => 'shortcut icon' , 'href' => UrlHelper::stripDangerousProtocols( $favicon ), 'type' => $type , ); } // Get the major Drupal version. list( $version , ) = explode ( '.' , \Drupal::VERSION); // Attach default meta tags. $meta_default = array ( // Make sure the Content-Type comes first because the IE browser may be // vulnerable to XSS via encoding attacks from any content that comes // before this META tag, such as a TITLE tag. 'system_meta_content_type' => array ( '#tag' => 'meta' , '#attributes' => array ( 'charset' => 'utf-8' , ), // Security: This always has to be output first. '#weight' => -1000, ), // Show Drupal and the major version number in the META GENERATOR tag. 'system_meta_generator' => array ( '#type' => 'html_tag' , '#tag' => 'meta' , '#attributes' => array ( 'name' => 'Generator' , ), ), // Attach default mobile meta tags for responsive design. 'MobileOptimized' => array ( '#tag' => 'meta' , '#attributes' => array ( 'name' => 'MobileOptimized' , 'content' => 'width' , ), ), 'HandheldFriendly' => array ( '#tag' => 'meta' , '#attributes' => array ( 'name' => 'HandheldFriendly' , 'content' => 'true' , ), ), 'viewport' => array ( '#tag' => 'meta' , '#attributes' => array ( 'name' => 'viewport' , 'content' => 'width=device-width, initial-scale=1.0' , ), ), ); foreach ( $meta_default as $key => $value ) { $page [ '#attached' ][ 'html_head' ][] = [ $value , $key ]; } // Handle setting the "active" class on links by: // - loading the active-link library if the current user is authenticated; // - applying a response filter if the current user is anonymous. // @see \Drupal\Core\Link // @see \Drupal\Core\Utility\LinkGenerator::generate() // @see template_preprocess_links() // @see \Drupal\Core\EventSubscriber\ActiveLinkResponseFilter if (\Drupal::currentUser()->isAuthenticated()) { $page [ '#attached' ][ 'library' ][] = 'core/drupal.active-link' ; } } |
Please login to continue.