function pwa_admin_configuration_manifest in Progressive Web App 7
Same name and namespace in other branches
- 7.2 pwa.admin.inc \pwa_admin_configuration_manifest()
Configure PWA settings for manifest.json
1 string reference to 'pwa_admin_configuration_manifest'
- pwa_menu in ./
pwa.module - Implements hook_menu().
File
- ./
pwa.admin.inc, line 10 - PWA administration forms.
Code
function pwa_admin_configuration_manifest() {
$form = [];
$form['manifest'] = [
'#type' => 'fieldset',
'#title' => 'manifest.json',
'#description' => t('The manifest file allows the website to be added to home screen as an app. <a href="@url" target="_blank" rel="noopener">See the W3C example</a>.', array(
'@url' => 'https://www.w3.org/TR/appmanifest/#example-manifest',
)),
];
$form['manifest']['pwa_short_name'] = [
'#type' => 'textfield',
'#title' => t('Short name'),
'#description' => t('Name of the shortcut created on the device. Should be like an app name (one short word or an acronym).'),
'#size' => 10,
'#default_value' => variable_get('pwa_short_name', variable_get('site_name')),
'#required' => TRUE,
];
$form['manifest']['pwa_name'] = [
'#type' => 'textfield',
'#title' => t('Name'),
'#description' => t('Usually appears as the name on the splash screen during launch.'),
'#size' => 30,
'#default_value' => variable_get('pwa_name', variable_get('site_name')),
'#required' => TRUE,
];
$form['manifest']['pwa_description'] = [
'#type' => 'textfield',
'#title' => t('Description'),
'#description' => t('A short description of the Progressive Web App. Answer the question "Why do I need this app?"'),
'#default_value' => variable_get('pwa_description', ''),
];
$form['manifest']['pwa_background_color'] = [
'#type' => 'textfield',
'#title' => t('Background color'),
'#description' => t('Color of the browser UI when launching from home screen.'),
'#size' => 8,
'#default_value' => variable_get('pwa_background_color', '#ffffff'),
];
$form['manifest']['pwa_theme_color'] = [
'#type' => 'textfield',
'#title' => t('Theme color'),
'#description' => t('Color of the background splash page when launching from home screen.'),
'#size' => 8,
'#default_value' => variable_get('pwa_theme_color', '#ffffff'),
];
if (module_exists('color')) {
$form['manifest']['pwa_background_color']['#value_callback'] = 'color_palette_color_value';
$form['manifest']['pwa_theme_color']['#value_callback'] = 'color_palette_color_value';
}
$form['manifest']['pwa_start_url'] = [
'#type' => 'textfield',
'#title' => t('Start URL'),
'#description' => t('Home page when launched from home screen. You can append a query string for analytics. For example <code>/home?startfrom=manifest</code>.'),
'#default_value' => variable_get('pwa_start_url', '/' . variable_get('site_frontpage', '')),
];
$form['manifest']['pwa_orientation'] = [
'#type' => 'select',
'#title' => t('Orientation'),
'#options' => [
'portrait' => t('Portrait'),
'landscape' => t('Landscape'),
],
'#default_value' => variable_get('pwa_orientation', 'portrait'),
];
$form['manifest']['pwa_display'] = [
'#type' => 'select',
'#title' => t('Display'),
'#options' => [
'fullscreen' => t('Full screen'),
'standalone' => t('Standalone'),
'minimal-ui' => t('Minimal UI'),
'browser' => t('Browser'),
],
'#description' => t('Determines whether the PWA will behave like a web page or a native app. <a href="@mdn-display" target="_blank" rel="noopener">Read more at MDN</a>.', [
'@mdn-display' => 'https://developer.mozilla.org/en-US/docs/Web/Manifest#display',
]),
'#default_value' => variable_get('pwa_display', 'standalone'),
];
$form['manifest']['pwa_icons'] = [
'#type' => 'item',
'#title' => t('Branding icons'),
'#description' => t('Use <code>hook_pwa_manifest_alter()</code> to configure custom icons. <a href="@manifest-example" target="_blank" rel="noopener">See official example</a>.', [
'@manifest-example' => 'https://cgit.drupalcode.org/pwa/tree/pwa.api.php?h=7.x-1.x#n13',
]),
'#default_value' => variable_get('pwa_icons', ''),
];
$form = system_settings_form($form);
// Wait for all the values to be saved before refreshing cache.
$form['#submit'][] = 'pwa_admin_configuration_submit';
return $form;
}