You are here

public function Manifest::getOutput in Progressive Web App 8

Same name and namespace in other branches
  1. 2.x src/Manifest.php \Drupal\pwa\Manifest::getOutput()

Build the manifest json string based on the configuration.

Return value

string Manifest JSON string.

Overrides ManifestInterface::getOutput

File

src/Manifest.php, line 40

Class

Manifest
Manifest JSON building service.

Namespace

Drupal\pwa

Code

public function getOutput() {

  // Get values.
  $values = $this
    ->getCleanValues();
  $manifest_data['orientation'] = 'portrait';
  if (isset($values['site_name'])) {
    $manifest_data['name'] = $values['site_name'];
  }
  if (isset($values['short_name'])) {
    $manifest_data['short_name'] = $values['short_name'];
  }
  if (isset($values['display'])) {
    $manifest_data['display'] = $values['display'];
  }
  if (isset($values['background_color'])) {
    $manifest_data['background_color'] = $values['background_color'];
  }
  if (isset($values['theme_color'])) {
    $manifest_data['theme_color'] = $values['theme_color'];
  }
  if (isset($values['description'])) {
    $manifest_data['description'] = $values['description'];
  }
  if (isset($values['lang'])) {
    $manifest_data['lang'] = $values['lang'];
  }
  if (isset($values['image'])) {
    $manifest_data['icons'][0]['src'] = $values['image'];
    $manifest_data['icons'][0]['sizes'] = '512x512';
    $manifest_data['icons'][0]['type'] = 'image/png';
    $manifest_data['icons'][0]['purpose'] = 'any maskable';
  }
  if (isset($values['image_small'])) {
    $manifest_data['icons'][1]['src'] = $values['image_small'];
    $manifest_data['icons'][1]['sizes'] = '192x192';
    $manifest_data['icons'][1]['type'] = 'image/png';
    $manifest_data['icons'][1]['purpose'] = 'any maskable';
  }
  if (isset($values['image_very_small'])) {
    $manifest_data['icons'][2]['src'] = $values['image_very_small'];
    $manifest_data['icons'][2]['sizes'] = '144x144';
    $manifest_data['icons'][2]['purpose'] = 'any maskable';
  }
  if (isset($values['start_url'])) {
    $manifest_data['start_url'] = $values['start_url'];
  }
  $manifest_data['scope'] = '/';
  \Drupal::moduleHandler()
    ->alter('pwa_manifest', $manifest_data);
  return Json::encode($manifest_data);
}