You are here

function hook_pwa_manifest_alter in Progressive Web App 7

Same name and namespace in other branches
  1. 8 pwa.api.php \hook_pwa_manifest_alter()
  2. 7.2 pwa.api.php \hook_pwa_manifest_alter()
  3. 2.x pwa.api.php \hook_pwa_manifest_alter()

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.

Parameters

array &$manifest Modified options that are used to build manifest.json:

1 invocation of hook_pwa_manifest_alter()
_pwa_manifest_data in ./pwa.module
Generate the for the manifest file.

File

./pwa.api.php, line 26
Hooks provided by the Progressive Web App module.

Code

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"
  $manifest['icons'] = [
    [
      'src' => url(drupal_get_path('theme', 'MY_THEME') . '/assets/logo-512.png'),
      'sizes' => '512x512',
      'type' => 'image/png',
    ],
    [
      'src' => url(drupal_get_path('theme', 'MY_THEME') . '/assets/logo-192.png'),
      'sizes' => '192x192',
      'type' => 'image/png',
    ],
    [
      'src' => url(drupal_get_path('theme', 'MY_THEME') . '/assets/logo-144.png'),
      'sizes' => '144x144',
      'type' => 'image/png',
    ],
    [
      'src' => url(drupal_get_path('theme', 'MY_THEME') . '/assets/logo.svg'),
      'type' => 'image/svg+xml',
    ],
  ];

  // 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';
}