Implements hook_system_info_alter().
Goes through a list of all modules that provide a field type and makes them required if there are any active fields of that type.
function field_system_info_alter(&$info, $file, $type) {
// It is not safe to call field_read_fields() during maintenance mode.
if ($type == 'module' && module_hook($file->name, 'field_info') && !defined('MAINTENANCE_MODE')) {
$fields = field_read_fields(array(
'module' => $file->name,
), array(
'include_deleted' => TRUE,
));
if ($fields) {
$info['required'] = TRUE;
// Provide an explanation message (only mention pending deletions if there
// remains no actual, non-deleted fields)
$non_deleted = FALSE;
foreach ($fields as $field) {
if (empty($field['deleted'])) {
$non_deleted = TRUE;
break;
}
}
if ($non_deleted) {
if (module_exists('field_ui')) {
$explanation = t('Field type(s) in use - see <a href="@fields-page">Field list</a>', array(
'@fields-page' => url('admin/reports/fields'),
));
}
else {
$explanation = t('Fields type(s) in use');
}
}
else {
$explanation = t('Fields pending deletion');
}
$info['explanation'] = $explanation;
}
}
}