diff --git a/boxes.install b/boxes.install index 9bf7f62..d7a9bb2 100644 --- a/boxes.install +++ b/boxes.install @@ -51,6 +51,7 @@ function boxes_schema() { 'export' => array( 'key' => 'delta', 'identifier' => 'box', + 'export callback' => 'boxes_box_export', 'api' => array( 'owner' => 'boxes', 'api' => 'box', diff --git a/boxes.module b/boxes.module index 0474e3d..137f44f 100644 --- a/boxes.module +++ b/boxes.module @@ -868,3 +868,39 @@ function boxes_ctools_block_info($module, $delta, &$info) { $info['category'] = t('Boxes'); } +/** + * Export callback to export a box. + */ +function boxes_box_export($object, $indent = '') { + $box = boxes_box_load($object->delta); + if ($box) { + return $box->export($object, $indent); + } + else { + watchdog('boxes', 'Export called for nonexistent box @delta', array('@delta' => $object->delta), WATCHDOG_WARNING); + return NULL; + } +} + +/** + * Implements hook_features_revert(). + */ +function box_features_revert($module) { + // Cache might be outdated during enabling of new module, kill it. + boxes_box_load_reset(); + if ($objects = features_get_default('box', $module)) { + foreach ($objects as $name => $object) { + if ($box = boxes_box_load($object->delta)) { + $box->revert($object, $module); + } + } + } +} + +/** + * Implements hook_features_rebuild(). + */ +function box_features_rebuild($module) { + box_features_revert($module); +} + diff --git a/plugins/boxes_box.inc b/plugins/boxes_box.inc index 46fd84b..32ca94c 100644 --- a/plugins/boxes_box.inc +++ b/plugins/boxes_box.inc @@ -142,6 +142,24 @@ abstract class boxes_box { return DRUPAL_CACHE_CUSTOM; } + + /** + * Export a block. Must return string of the export. + */ + public function export($object, $indent) { + return ctools_export_object('box', $object, $indent); + } + + /** + * Revert a box. + */ + public function revert($object, $module) { + $object = ctools_export_crud_load('box', $this->delta); + if ($object && ($object->export_type & EXPORT_IN_DATABASE)) { + _ctools_features_export_crud_delete('box', $object); + } + } + /** * Declare default options. */