acsf.module in Acquia Cloud Site Factory Connector 8.2
Same filename and directory in other branches
Acquia Cloud Site Factory Connector.
File
acsf.moduleView source
<?php
/**
* @file
* Acquia Cloud Site Factory Connector.
*/
use Drupal\acsf\AcsfSite;
use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_modules_installed().
*/
function acsf_modules_installed($modules) {
acsf_build_registry();
}
/**
* Builds the registry of ACSF compatible class files.
*/
function acsf_build_registry() {
// Create a registry of ACSF compatible classes.
$registry = \Drupal::moduleHandler()
->invokeAll('acsf_registry');
usort($registry['events'], 'acsf_registry_sort');
\Drupal::service('acsf.variable_storage')
->set('acsf_registry', $registry);
}
/**
* Determines sort order for usort.
*/
function acsf_registry_sort($a, $b) {
if (!isset($a['weight'])) {
$a['weight'] = 0;
}
if (!isset($b['weight'])) {
$b['weight'] = 0;
}
if ($a['weight'] == $b['weight']) {
return 0;
}
return $a['weight'] < $b['weight'] ? -1 : 1;
}
/**
* Retrieves the registry of class files.
*/
function acsf_get_registry() {
return \Drupal::service('acsf.variable_storage')
->get('acsf_registry', []);
}
/**
* Implements hook_acsf_registry().
*/
function acsf_acsf_registry() {
return [
'events' => [
[
'weight' => -1,
'type' => 'acsf_install',
'class' => '\\Drupal\\acsf\\Event\\AcsfSiteInfoHandler',
],
],
];
}
/**
* Implements hook_cron().
*/
function acsf_cron() {
// Don't execute on non-ACSF systems, which cannot recognize the current site.
if (!empty($GLOBALS['gardens_site_settings']['conf']['acsf_site_id'])) {
// Periodically refresh the site data.
$site = AcsfSite::load();
$refresh_age = time() - 86400;
if ($site->last_sf_refresh < $refresh_age) {
$site
->refresh();
}
}
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function acsf_form_system_site_maintenance_mode_alter(&$form, FormStateInterface $form_state, $form_id) {
$messenger = \Drupal::messenger();
$acsf_maintenance_time = \Drupal::config('acsf.settings')
->get('maintenance_time');
$maintenance_mode = \Drupal::state()
->get('system.maintenance_mode');
if ($acsf_maintenance_time && $maintenance_mode) {
$messenger
->addMessage(t('ACSF site maintenance in progress.'), 'warning');
if (\Drupal::time()
->getRequestTime() > $acsf_maintenance_time) {
// The update is taking longer than expected.
$messenger
->addMessage(t('The maintenance was expected to be done already - please be patient. Reload this page to see if maintenance is complete.'), 'warning');
}
else {
// Never show an interval less than 1 minute.
$remaining = \Drupal::service('date.formatter')
->formatInterval(60 + $acsf_maintenance_time - \Drupal::time()
->getRequestTime(), 1);
$messenger
->addMessage(t('The maintenance should be completed within :interval. Reload this page to see if maintenance is complete.', [
':interval' => $remaining,
]), 'warning');
}
$form['maintenance_mode']['#attributes']['disabled'][] = 'disabled';
}
}
Functions
Name | Description |
---|---|
acsf_acsf_registry | Implements hook_acsf_registry(). |
acsf_build_registry | Builds the registry of ACSF compatible class files. |
acsf_cron | Implements hook_cron(). |
acsf_form_system_site_maintenance_mode_alter | Implements hook_form_FORM_ID_alter(). |
acsf_get_registry | Retrieves the registry of class files. |
acsf_modules_installed | Implements hook_modules_installed(). |
acsf_registry_sort | Determines sort order for usort. |