paragraphs.features.inc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * @file
  4. * Holds features implementation.
  5. */
  6. /**
  7. * Implements hook_features_export_options().
  8. */
  9. function paragraphs_features_export_options() {
  10. $bundles = paragraphs_bundle_load();
  11. $names = array();
  12. foreach ($bundles as $key => $value) {
  13. $names[$key] = $value->name;
  14. }
  15. return $names;
  16. }
  17. /**
  18. * Implements hook_features_export().
  19. */
  20. function paragraphs_features_export($data, &$export, $module_name = '') {
  21. $pipe = array();
  22. $map = features_get_default_map('paragraphs');
  23. foreach ($data as $type) {
  24. if ($info = paragraphs_bundle_load($type)) {
  25. $export['features']['paragraphs'][$type] = $type;
  26. $export['dependencies']['paragraphs'] = 'paragraphs';
  27. $export['dependencies']['features'] = 'features';
  28. $fields = field_info_instances('paragraphs_item', $type);
  29. foreach ($fields as $name => $field) {
  30. $pipe['field_instance'][] = "paragraphs_item-{$field['bundle']}-{$field['field_name']}";
  31. }
  32. }
  33. }
  34. return $pipe;
  35. }
  36. /**
  37. * Implements hook_features_export_render().
  38. */
  39. function paragraphs_features_export_render($module, $data, $export = NULL) {
  40. $elements = array(
  41. 'name' => FALSE,
  42. 'bundle' => FALSE,
  43. 'locked' => FALSE,
  44. );
  45. $output = array();
  46. $output[] = ' $items = array(';
  47. foreach ($data as $type) {
  48. if ($info = paragraphs_bundle_load($type)) {
  49. $output[] = " '{$type}' => array(";
  50. foreach ($elements as $key => $t) {
  51. if ($t) {
  52. $text = str_replace("'", "\'", $info->$key);
  53. $text = !empty($text) ? "t('{$text}')" : "''";
  54. $output[] = " '{$key}' => {$text},";
  55. }
  56. else {
  57. $output[] = " '{$key}' => '{$info->$key}',";
  58. }
  59. }
  60. $output[] = " ),";
  61. }
  62. }
  63. $output[] = ' );';
  64. $output[] = ' return $items;';
  65. $output = implode("\n", $output);
  66. return array('paragraphs_info' => $output);
  67. }
  68. /**
  69. * Implements hook_features_revert().
  70. *
  71. * @param $module
  72. * name of module to revert content for
  73. */
  74. function paragraphs_features_revert($module = NULL) {
  75. if ($default_types = features_get_default('paragraphs', $module)) {
  76. foreach ($default_types as $type_name => $type_info) {
  77. db_delete('paragraphs_bundle')
  78. ->condition('bundle', $type_name)
  79. ->execute();
  80. $bundle = new stdClass();
  81. $bundle->bundle = $type_info['bundle'];
  82. $bundle->locked = $type_info['locked'];
  83. $bundle->name = $type_info['name'];
  84. paragraphs_bundle_save($bundle);
  85. }
  86. paragraphs_bundle_load(NULL, TRUE);
  87. menu_rebuild();
  88. }
  89. }
  90. /**
  91. * Implements hook_features_rebuild().
  92. */
  93. function paragraphs_features_rebuild($module_name) {
  94. paragraphs_features_revert($module_name);
  95. }