function d3_requirements in d3.js 7
Implements hook_requirements().
File
- ./
d3.install, line 10 - Install, update and uninstall functions for the d3 module.
Code
function d3_requirements($phase) {
$requirements = array();
// Run only for reporting.
if ($phase != 'runtime') {
return $requirements;
}
// If this is run during install we'll need to use get_t instead of just t.
$t = get_t();
// If the library directory exists.
$d3 = libraries_load('d3');
$requirements['d3'] = array(
'title' => $t('D3'),
'value' => '',
'severity' => REQUIREMENT_OK,
);
// Installed indicated by hook_libraries_info().
if (!empty($d3['installed'])) {
$requirements['d3']['severity'] = REQUIREMENT_OK;
// If CDN is checked, d3 will add this to the library info.
if (!empty($d3['cdn'])) {
$requirements['d3']['value'] .= "D3 CDN v{$d3['version']} linked correctly.";
}
else {
$requirements['d3']['value'] = "D3 v{$d3['version']} installed correctly.";
}
}
else {
$requirements['d3']['severity'] = REQUIREMENT_ERROR;
// Check and see if the library directory is there at all.
if (!($path = libraries_get_path('d3'))) {
$requirements['d3']['value'] .= 'D3 library folder does not exist.';
}
else {
$requirements['d3']['value'] .= $t('D3 library folder exists (!path), but no file d3.min.js found.', array(
'!path' => $path,
));
}
$requirements['d3']['value'] .= $t('!download the library and place all
javascript files in a folder entitled "d3" located in your default
libraries folder. E.g. sites/all/libraries/d3/d3.min.js.', array(
'!download' => l($t('Download'), 'https://d3js.org/'),
));
}
return $requirements;
}