You are here

d3.install in d3.js 7

Install, update and uninstall functions for the d3 module.

File

d3.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the d3 module.
 */

/**
 * Implements hook_requirements().
 */
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;
}

/**
 * Implements hook_uninstall().
 */
function d3_uninstall() {
  variable_del('d3_graphapi_default_library');
}

Functions

Namesort descending Description
d3_requirements Implements hook_requirements().
d3_uninstall Implements hook_uninstall().