pwa.api.php in Progressive Web App 7.2
Same filename and directory in other branches
Hooks provided by the Progressive Web App module.
File
pwa.api.phpView source
<?php
/**
* @file
* Hooks provided by the Progressive Web App module.
*/
/**
* @addtogroup hooks
* @{
*/
/**
* Manually alter manifest.json
*
* This hook allows manual configuration of the manifest.json file. Some of the
* options can be configured in the admin settings of the module, but it can all
* be altered within the hook.
*
* After you make your modifications you do NOT need to return the results.
* Since $manifest is passed by reference, any changes made to $manifest are
* automatically registered.
*
* @param array &$manifest Modified options that are used to build manifest.json
*/
function hook_pwa_manifest_alter(&$manifest) {
// Change a string-based property.
$manifest['name'] = variable_get('pwa_name', variable_get('site_name'));
// Change array-based properties. In this case we're manually specifying which
// icons will appear in the manifest. Normally you have to specify each size
// listed here to meet criteria for "Add to Homescreen"
$theme_path = drupal_get_path('theme', 'MY_THEME');
$manifest['icons'] = [
[
'src' => file_create_url($theme_path . '/assets/logo-512.png'),
'sizes' => '512x512',
'type' => 'image/png',
'purpose' => 'any maskable',
],
[
'src' => file_create_url($theme_path . '/assets/logo-192.png'),
'sizes' => '192x192',
'type' => 'image/png',
'purpose' => 'any maskable',
],
[
'src' => file_create_url($theme_path . '/assets/logo.svg'),
'sizes' => '512x512',
'type' => 'image/svg+xml',
'purpose' => 'any maskable',
],
];
// Add a new parameter
//
// Here we are specifying `orientation`. If your website is designed to be
// viewed ONLY in landscape, the `orientation` setting can help the PWA look
// good while the splash/loading screens are displaying.
//
// We omit this property by default from the module for accessibility reasons.
// For more information see the d.o issue and WCAG documentation:
//
// @see https://www.drupal.org/project/pwa/issues/3070058
// @see https://www.w3.org/WAI/WCAG21/Understanding/orientation.html
$manifest['orientation'] = 'landscape';
}
/**
* @} End of "addtogroup hooks".
*/
Functions
Name![]() |
Description |
---|---|
hook_pwa_manifest_alter | Manually alter manifest.json |