diff --git a/metatag.module b/metatag.module index 4cfe352..32913d4 100644 --- a/metatag.module +++ b/metatag.module @@ -1216,3 +1216,91 @@ function metatag_config_access($op, $config = NULL) { return FALSE; } + +/** + * Implements of hook_features_api(). + */ +function metatag_features_api() { + $components = array( + 'metatags' => array( + 'name' => t('metatags'), + 'features_source' => TRUE, + 'default_hook' => 'metatag_export_default', + 'default_file' => FEATURES_DEFAULTS_INCLUDED, + ), + ); + return $components; +} + +/** + * Implements hook_features_export(). + */ +function metatags_features_export($data, &$export, $module_name = '', $type = 'metatags') { + $pipe = array(); + + foreach ($data as $name) { + $export['features'][$type][$name] = metatag_config_load($name); + } + + return $pipe; +} + +/** + * Implements hook_features_export_render(). + */ +function metatags_features_export_render($module_name, $data, $export = NULL) { + $code = array(); + $code[] = ' $config = array();'; + $code[] = ''; + + foreach ($data as $key => $name) { + if (is_object($name)) { + $name = $name->instance; + } + if ($config = metatag_config_load($name)) { + $export = new stdClass(); + $export->instance = $config->instance; + $export->config = $config->config; + $export = features_var_export($export, ' '); + $key = features_var_export($name); + $code[] = " // Exported metatags config instance: {$name}."; + $code[] = " \$config[{$key}] = {$export};"; + $code[] = ""; + } + } + $code[] = ' return $config;'; + $code = implode("\n", $code); + return array('metatag_export_default' => $code); +} + +/** + * Implements hook_features_revert(). + */ +function metatags_features_revert($module) { + $function = "{$module}_metatag_export_default"; + $feature_conf = $function(); + if ($default_config = features_get_default('metatags')) { + foreach (array_keys($default_config) as $config) { + if ($conf = metatag_config_load($config)) { + db_delete('metatag_config')->condition('instance', $config)->execute(); + } + unset($feature_conf[$config]['cid']); + $object = new stdClass(); + $object->cid = NULL; + $object->instance = $config; + $object->config = $feature_conf[$config]['config']; + metatag_config_save($object); + } + } +} + +/** + * Implements hook_features_export_options(). + */ +function metatags_features_export_options() { + $instances = metatag_config_instance_info(); + foreach ($instances as $key => $instance) { + $options[$key] = $key; + }; + return $options; +}