metatag.features.inc 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * @file
  4. * Features integration for the Metatag module.
  5. */
  6. /**
  7. * Implements hook_features_export().
  8. */
  9. function metatag_features_export($data, &$export, $module_name = '', $type = 'metatag') {
  10. $pipe = array();
  11. foreach ($data as $name) {
  12. if (metatag_config_load($name)) {
  13. $export['features'][$type][$name] = $name;
  14. }
  15. }
  16. $export['dependencies']['metatag'] = 'metatag';
  17. return $pipe;
  18. }
  19. /**
  20. * Implements hook_features_export_render().
  21. */
  22. function metatag_features_export_render($module_name, $data, $export = NULL) {
  23. $code = array();
  24. $code[] = ' $config = array();';
  25. $code[] = '';
  26. foreach ($data as $key => $name) {
  27. if (is_object($name)) {
  28. $name = $name->instance;
  29. }
  30. if ($config = metatag_config_load($name)) {
  31. $export = new stdClass();
  32. $export->instance = $config->instance;
  33. if (isset($config->disabled)) {
  34. $export->disabled = $config->disabled;
  35. }
  36. $export->config = $config->config;
  37. $export = features_var_export($export, ' ');
  38. $key = features_var_export($name);
  39. $code[] = " // Exported Metatag config instance: {$name}.";
  40. $code[] = " \$config[{$key}] = {$export};";
  41. $code[] = "";
  42. }
  43. }
  44. $code[] = ' return $config;';
  45. $code = implode("\n", $code);
  46. return array('metatag_export_default' => $code);
  47. }
  48. /**
  49. * Implements hook_features_revert().
  50. */
  51. function metatag_features_revert($module) {
  52. if ($feature_conf = features_get_default('metatag', $module)) {
  53. foreach (array_keys($feature_conf) as $config) {
  54. if ($conf = metatag_config_load($config)) {
  55. db_delete('metatag_config')->condition('instance', $config)->execute();
  56. }
  57. unset($feature_conf[$config]['cid']);
  58. $object = new stdClass();
  59. $object->cid = NULL;
  60. $object->instance = $config;
  61. $object->config = $feature_conf[$config]['config'];
  62. metatag_config_save($object);
  63. if (!empty($feature_conf[$config]['disabled'])) {
  64. ctools_export_crud_disable('metatag_config', $config);
  65. }
  66. else {
  67. ctools_export_crud_enable('metatag_config', $config);
  68. }
  69. }
  70. }
  71. }
  72. /**
  73. * Implements hook_features_export_options().
  74. */
  75. function metatag_features_export_options() {
  76. $instances = metatag_config_instance_info();
  77. foreach ($instances as $key => $instance) {
  78. $options[$key] = $key;
  79. };
  80. return $options;
  81. }
  82. /**
  83. * Implements hook_features_rebuild().
  84. */
  85. function metatag_features_rebuild($module) {
  86. metatag_features_revert($module);
  87. }