swup-1.0.0-alpha1/swup.install
swup.install
<?php
/**
* @file
* Install, update, uninstall Requirements functions for the Swup module.
*/
define('SWUP_CDN_URL', 'https://unpkg.com/swup@4');
define('SWUP_COMPOSER_INSTALL_INFO', 'https://www.drupal.org/docs/develop/using-composer/using-composer-to-install-drupal-and-manage-dependencies');
/**
* Implements hook_requirements().
*/
function swup_requirements($phase) {
$requirements = [];
if ($phase != 'runtime') {
return $requirements;
}
// Check if Swup library is installed locally.
$swup_exists = swup_check_installed();
// Get using Swup version.
$version = $swup_exists ? swup_detect_version() : '4.8.2';
// Show the status of the library in the status report section.
if ($swup_exists) {
$status = t('Installed locally <em>(Version @version)</em>', ['@version' => $version]);
$description = t('The Swup.js library was found in the local libraries path and enabled.');
}
else {
$status = t('Using CDN <em>(Version @version)</em>', ['@version' => $version]);
$description = t('The Swup.js library is loaded from <strong>CDN</strong> (unpkg).<br>For local installation, use Composer with Asset Packagist to install npm-asset/swup to "/libraries/swup".<br>See <a href="@composerUrl" rel="external" target="_blank">Composer documentation</a> for details.', [
'@composerUrl' => SWUP_COMPOSER_INSTALL_INFO,
]);
}
$requirements['swup'] = [
'title' => t('Swup.js library'),
'value' => $status,
'severity' => REQUIREMENT_OK,
'description' => $description,
];
return $requirements;
}
/**
* Implements hook_install().
*/
function swup_install() {
// Check for Swup.js library local installation.
$library_exists = swup_check_installed();
if (!$library_exists) {
\Drupal::messenger()->addWarning(t('The Swup module will use the <strong>CDN version</strong> of Swup.js.<br>For local installation, use Composer with Asset Packagist to install npm-asset/swup.'));
}
\Drupal::messenger()->addMessage(t('Thanks for installing Swup module.'));
}
