Skip to content

Instantly share code, notes, and snippets.

@dirtystylus
Created April 5, 2017 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dirtystylus/f3b0897fb96abaed669433526dea092a to your computer and use it in GitHub Desktop.
Save dirtystylus/f3b0897fb96abaed669433526dea092a to your computer and use it in GitHub Desktop.
Hook Presave and Delete
<?php
/**
* @file
* Field DOS Feed Status Module file
*
* This module allows site administrators to send a stock warning
* email to a specified user or users through the admin interface.
* Administrators can configure the default email including token replacement.
*/
//define('EXHIBIT_ITEMS_MODIFICATION_DATE', 'none');
/**
* Implements hook_help().
*/
function field_dos_feed_status_help($path, $arg) {
if ($path == 'admin/help#field_dos_feed_status') {
return t('Field DOS feed status maintains timestamps for the last modification (add/delete/update) of content types and taxonomies.');
}
}
/**
* Implements hook_menu().
*/
function field_dos_feed_status_menu() {
$items = array();
$items['api/feed-status.json'] = array(
'access callback' => true, // available to all
'page callback' => 'field_dos_feed_status_menu_object', // defined below
'delivery callback' => 'drupal_json_output'
);
return $items;
}
/**
* Implements hook_node_presave().
*/
function field_dos_feed_status_node_presave($node) {
switch ($node->type) {
case 'amenity':
variable_set('amenities_timestamp', time());
break;
case 'behind_scenes_item':
variable_set('behind_scenes_items_timestamp', time());
break;
case 'collection_highlight':
variable_set('collection_highlights_timestamp', time());
break;
case 'exhibit_item':
variable_set('exhibit_items_timestamp', time());
break;
case 'schedule_item':
variable_set('schedule_items_timestamp', time());
break;
case 'touchscreen_station':
variable_set('touchscreen_stations_timestamp', time());
break;
case 'itinerary':
variable_set('itineraries_timestamp', time());
break;
default:
break;
}
}
/**
* Implements hook_node_delete().
*/
function field_dos_feed_status_node_delete($node) {
switch ($node->type) {
case 'amenity':
variable_set('amenities_timestamp', time());
break;
case 'behind_scenes_item':
variable_set('behind_scenes_items_timestamp', time());
break;
case 'collection_highlight':
variable_set('collection_highlights_timestamp', time());
break;
case 'exhibit_item':
variable_set('exhibit_items_timestamp', time());
break;
case 'schedule_item':
variable_set('schedule_items_timestamp', time());
break;
case 'touchscreen_station':
variable_set('touchscreen_stations_timestamp', time());
break;
case 'itinerary':
variable_set('itineraries_timestamp', time());
break;
default:
break;
}
}
/**
* Implements hook_taxonomy_term_presave().
*/
function field_dos_feed_status_taxonomy_term_presave($term) {
switch ($term->vocabulary_machine_name) {
case 'amenity_category':
variable_set('amenity_categories_timestamp', time());
break;
case 'location':
variable_set('locations_timestamp', time());
break;
default:
# code...
break;
}
}
/**
* Implements hook_taxonomy_term_delete().
*/
function field_dos_feed_status_taxonomy_term_delete($term) {
switch ($term->vocabulary_machine_name) {
case 'amenity_category':
variable_set('amenity_categories_timestamp', time());
break;
case 'location':
variable_set('locations_timestamp', time());
break;
default:
# code...
break;
}
}
function field_dos_feed_status_menu_object() {
$feeds = array(
array('amenities' => variable_get('amenities_timestamp', '')),
array('amenity-categories' => variable_get('amenity_categories_timestamp', '')),
array('behind-the-scenes-items' => variable_get('behind_scenes_items_timestamp', '')),
array('collection-highlights' => variable_get('collection_highlights_timestamp', '')),
array('exhibit-items' => variable_get('exhibit_items_timestamp', '')),
array('itineraries' => variable_get('itineraries_timestamp', '')),
array('locations' => variable_get('locations_timestamp', '')),
array('schedule' => variable_get('schedule_items_timestamp', '')),
array('touchscreen-stations' => variable_get('touchscreen_stations_timestamp', '')),
);
return $feeds;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment