Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
68 lines (62 sloc) 1.97 KB
<?php
/**
* @file
* Install file for Digital Strategy module.
*/
// On module enable create nodes and set digital strategy type variables
function digital_strategy_enable() {
variable_set('digital_strategy_types', array("xml", "json", "jsonp", "html"));
digital_strategy_create_nodes();
}
// On module disable delete nodes and digital strategy type variables
function digital_strategy_disable() {
foreach (variable_get('digital_strategy_types', array("xml", "json", "jsonp", "html")) as $type) {
$alias = "digitalstrategy/" . $type;
// to delete the html page alias will be digitalstrategy/report
if ($type == 'html') {
$alias = "digitalstrategy/report";
}
$path = drupal_lookup_path("source", $alias);
$node = menu_get_object("node", 1, $path);
if ($node) {
node_delete($node->nid);
}
else {
drupal_set_message(t('@alias not deleted, it did not exist.', array('@alias' => $alias)), 'warning');
}
}
variable_del('strategy_types');
}
// Creates the nodes for the digital strategy type variables
function digital_strategy_create_nodes() {
foreach (variable_get('digital_strategy_types', array("xml", "json", "jsonp", "html")) as $type) {
$node = new stdClass();
$node->name = "Digital Strategy Progess - " . $type;
$node->title = $node->name;
$node->body = "";
$node->type = "page";
$node->created = time();
$node->changed = $node->created;
$node->status = 0;
$node->promote = 0;
$node->sticky = 0;
$node->format = 2;
if (module_exists("pathauto")) {
$node->pathauto_perform_alias = 0;
}
if (module_exists("apachesolr_exclude")) {
$node->apachesolr_exclude = 1;
}
$node->path = "digitalstrategy/" . $type;
// change the path for the html version
if ($type == 'html') {
$node->path = "digitalstrategy/report";
if (module_exists("apachesolr_exclude")) {
$node->apachesolr_exclude = 0;
}
}
if ($node = node_submit($node)) {
node_save($node);
}
} // end foreach
}