3
0
Fork 0
mirror of https://github.com/farmOS/farmOS.git synced 2024-02-23 11:37:38 +01:00
farmOS/farm.install
Michael Stenta 11c2f324e1 Issue #3183739: Functional tests are installing all default farmOS modules
This is a temporary first step, but not a proper solution to the issue.
2020-11-20 11:35:13 -05:00

98 lines
2.7 KiB
PHP

<?php
/**
* @file
* Install, update and uninstall functions for the farmOS installation profile.
*/
/**
* Implements hook_install_tasks().
*/
function farm_install_tasks(&$install_state) {
// Add tasks for enabling farmOS modules.
$tasks = [
'\Drupal\farm\Form\FarmModulesForm' => [
'display_name' => t('Install modules'),
'type' => 'form',
],
'farm_install_modules' => [
'type' => 'batch',
],
];
return $tasks;
}
/**
* Implements hook_install_tasks_alter().
*/
function farm_install_tasks_alter(&$tasks, $install_state) {
// Override install task display names to replace "site" with "farmOS".
$alter_display_names = [
'install_profile_modules' => t('Install farmOS'),
'install_configure_form' => t('Configure farmOS'),
];
foreach ($alter_display_names as $task => $display_name) {
if (!empty($tasks[$task]['display_name'])) {
$tasks[$task]['display_name'] = $display_name;
}
}
}
/**
* Installs farmOS modules via a batch process.
*
* @param array $install_state
* An array of information about the current installation state.
*
* @return array
* The batch definition.
*/
function farm_install_modules(array &$install_state) {
// Load the list of modules that should be installed. This state is set by
// the \Drupal\farm\Form\FarmModulesForm submit method.
$modules = \Drupal::state()->get('farm.install_modules') ?: [];
// If this is running in the context of a functional test, do not install any
// additional modules. This is a temporary hack.
// @see Drupal\Tests\farm\Functional\FarmBrowserTestBase::setUp()
// @todo https://www.drupal.org/project/farm/issues/3183739
if (!empty($GLOBALS['farm_test'])) {
$modules = [];
}
// Load a list of all available modules, so that we can display their names.
$module_handler = \Drupal::service('module_handler');
// Assemble the batch operation for installing modules.
$operations = [];
foreach ($modules as $module => $weight) {
$operations[] = [
'_farm_install_module_batch',
[
$module,
$module_handler->getName($module),
],
];
}
$batch = [
'operations' => $operations,
'title' => t('Installing @drupal modules', ['@drupal' => drupal_install_profile_distribution_name()]),
'error_message' => t('The installation has encountered an error.'),
];
return $batch;
}
/**
* Implements callback_batch_operation().
*
* Performs batch installation of farmOS modules.
*/
function _farm_install_module_batch($module, $module_name, &$context) {
\Drupal::service('module_installer')->install([$module], TRUE);
$context['results'][] = $module;
$context['message'] = t('Installed %module module.', ['%module' => $module_name]);
}