You are here

function pwa_menu in Progressive Web App 7.2

Same name and namespace in other branches
  1. 7 pwa.module \pwa_menu()

Implements hook_menu().

File

./pwa.module, line 38

Code

function pwa_menu() {
  $items = [];

  // Clear the user storage with the Site-Data-Clear header.
  // Use the ?destination parameter to redirect the user to a page after
  // clearing the storage.
  $items['pwa/storage/clear'] = [
    'page callback' => 'pwa_serviceworker_clear',
    'access arguments' => [
      'access pwa',
    ],
    'type' => MENU_CALLBACK,
  ];

  // Callback for the phone home feature.
  $items['pwa/serviceworker/check'] = [
    'page callback' => 'pwa_module_active',
    'access callback' => '_pwa_access_check',
    'delivery callback' => 'pwa_deliver_json',
    'file' => 'pwa.pages.inc',
    'type' => MENU_CALLBACK,
  ];

  // The JS of the serviceworker file.
  $items['pwa/serviceworker/js'] = [
    'page callback' => 'pwa_file_data',
    'page arguments' => [
      'serviceworker',
    ],
    'access callback' => '_pwa_access_check',
    'delivery callback' => 'pwa_deliver_serviceworker_file',
    'file' => 'pwa.pages.inc',
    'type' => MENU_CALLBACK,
  ];
  $items['manifest.webmanifest'] = [
    'page callback' => 'pwa_file_data',
    'page arguments' => [
      'manifest',
    ],
    'access callback' => TRUE,
    'delivery callback' => 'pwa_deliver_manifest_file',
    'file' => 'pwa.pages.inc',
    'type' => MENU_CALLBACK,
  ];
  $items['offline'] = [
    'page callback' => 'pwa_offline_page',
    'access callback' => '_pwa_access_check',
    'file' => 'pwa.pages.inc',
    'type' => MENU_CALLBACK,
  ];
  $items['admin/config/pwa'] = [
    'title' => t('Progressive Web App'),
    'description' => t('Progressive Web App configuration.'),
    'position' => 'right',
    'page callback' => 'system_admin_menu_block_page',
    'access arguments' => [
      'access administration pages',
    ],
    'file' => 'system.admin.inc',
    'file path' => drupal_get_path('module', 'system'),
    'weight' => 10,
  ];

  // Specify manifest settings as default landing page when using system nav.
  $items['admin/config/pwa/settings'] = [
    'title' => t('PWA information'),
    'description' => t('Control how your website appears on mobile devices when used as a PWA.'),
    'page callback' => 'drupal_get_form',
    'page arguments' => [
      'pwa_admin_configuration',
    ],
    'access arguments' => [
      'administer pwa manifest',
    ],
    'file' => 'pwa.admin.inc',
    'type' => MENU_NORMAL_ITEM,
    'weight' => -10,
  ];

  // Admin settings for manifest.json
  $items['admin/config/pwa/settings/main'] = [
    'title' => t('Add to Homescreen'),
    'type' => MENU_DEFAULT_LOCAL_TASK,
  ] + $items['admin/config/pwa/settings'];

  // Admin settings for manifest.json
  $items['admin/config/pwa/settings/manifest'] = [
    'title' => t('Manifest'),
    'page arguments' => [
      'pwa_admin_configuration_manifest',
    ],
    'type' => MENU_LOCAL_TASK,
  ] + $items['admin/config/pwa/settings'];

  // Admin settings for manifest.json
  $items['admin/config/pwa/settings/serviceworker'] = [
    'title' => t('ServiceWorker'),
    'page arguments' => [
      'pwa_admin_configuration_sw',
    ],
    'access arguments' => [
      'administer pwa serviceworker',
    ],
    'type' => MENU_LOCAL_TASK,
  ] + $items['admin/config/pwa/settings'];

  // Admin settings to control how SW is loaded and cached.
  $items['admin/config/pwa/cache'] = [
    'title' => t('Offline Cache'),
    'description' => t('Configure offline cache and caching strategies.'),
    'page callback' => 'drupal_get_form',
    'page arguments' => [
      'pwa_admin_configuration_sw_patterns',
    ],
    'access arguments' => [
      'administer pwa serviceworker',
    ],
    'file' => 'pwa.admin.inc',
    'type' => MENU_NORMAL_ITEM,
  ];
  $items['admin/config/pwa/cache/patterns'] = [
    'title' => t('Cache patterns & strategies'),
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => -1,
  ] + $items['admin/config/pwa/cache'];
  $items['admin/config/pwa/cache/precache'] = [
    'title' => t('Precaching'),
    'page arguments' => [
      'pwa_admin_configuration_sw_precache',
    ],
    'type' => MENU_LOCAL_TASK,
  ] + $items['admin/config/pwa/cache'];
  return $items;
}