client_hints-8.x-1.0-alpha3/modules/client_hints_image_formatter/client_hints_image_formatter.module
modules/client_hints_image_formatter/client_hints_image_formatter.module
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 | <?php /** * Implements hook_theme_registry_alter(). */ function client_hints_image_formatter_theme_registry_alter(& $theme_registry ) { $theme_registry [ 'image__client_hints' ][ 'path' ] = \Drupal::service( 'module_handler' )->getModule( 'client_hints_image_formatter' )->getPath() . '/templates' ; $theme_registry [ 'image__client_hints' ][ 'template' ] = 'image--client-hints' ; } /** * Implements template_preprocess_image__client_hints(). */ function client_hints_image_formatter_preprocess_image__client_hints(& $variables ) { // Set processed url as clientHintsSrc data attribute. $variables [ 'attributes' ][ 'data-client-hints-src' ] = $variables [ 'uri' ]; // Set an appropriately sized transparent svg as placeholder image. $variables [ 'attributes' ][ 'src' ] = _client_hints_placeholder_svg( $variables [ 'width' ], $variables [ 'height' ]); // Add Javascript library. $variables [ '#attached' ][ 'library' ][] = 'client_hints/lazy' ; } /** * Implements template_preprocess_image__client_hints(). */ function client_hints_image_formatter_preprocess_image_formatter__client_hints(& $variables ) { $variables [ 'image' ][ '#theme' ] = 'image__client_hints' ; } |