[development] Installation -- Can A Module "Refuse" To Be
Installed?
Earl Miles
merlin at logrus.com
Sun Apr 9 00:57:58 UTC 2006
Rob Thorne wrote:
> I've started to write .install files for the modules I'm responsible
> for. Mostly this is pretty straightforward. But there are a few areas
> I'm hoping there is support for in the system:
>
> * UI for problems/status during install: I've made it a practice to
> do like merlinofchaos and put up a message to indicate I've
> installed tables (with a call to drupal_set_message). It's less
> clear what's best to call if there's a problem.
> * I've noticed that there are calls in install.inc to register
> schema versions, but I haven't seen any examples of their being
> used. How *should* those functions be used?
> * Dependencies are an issue for some of the stuff I'm installing.
> It would be a good thing if the .install could detect that a
> needed module was not present, and in that case, put up an error
> message and refuse to install. Is there a mechanism to do this
> currently?
cut & paste cause I lazy
/**
* hunmonk's module dependency check: see http://drupal.org/node/54463
*/
function views_ui_form_alter($form_id, &$form) {
if ($form_id == 'system_modules' && !$_POST) {
views_ui_system_module_validate($form);
}
}
/**
* hunmonk's module dependency check: see http://drupal.org/node/54463
*/
function views_ui_system_module_validate(&$form) {
$module = 'views_ui';
$dependencies = array('views');
foreach ($dependencies as $dependency) {
if (!in_array($dependency, $form['status']['#default_value'])) {
$missing_dependency = TRUE;
$missing_dependency_list[] = $dependency;
}
}
if (in_array($module, $form['status']['#default_value']) &&
isset($missing_dependency)) {
db_query("UPDATE {system} SET status = 0 WHERE type = 'module' AND name =
'%s'", $module);
$key = array_search($module, $form['status']['#default_value']);
unset($form['status']['#default_value'][$key]);
drupal_set_message(t('The module %module was deactivated--it requires the
following disabled/non-existant modules to function properly: %dependencies',
array('%module' => $module, '%dependencies' => implode(', ',
$missing_dependency_list))), 'error');
}
}
More information about the development
mailing list