delta_injection.inc

  1. nittany7 modules/contrib/delta/plugins/delta/delta_injection.inc
  2. cis7 modules/contrib/delta/plugins/delta/delta_injection.inc
  3. mooc7 modules/contrib/delta/plugins/delta/delta_injection.inc

Classes

Namesort descending Description
delta_injection

File

modules/contrib/delta/plugins/delta/delta_injection.inc
View source
  1. <?php
  2. class delta_injection {
  3. var $plugin;
  4. var $delta;
  5. var $original;
  6. var $settings;
  7. /**
  8. * Constructor. Do not override.
  9. */
  10. function __construct($plugin, $delta) {
  11. $this->plugin = $plugin;
  12. $this->delta = delta_load($delta);
  13. }
  14. /**
  15. * @todo
  16. */
  17. function variables() {
  18. return array();
  19. }
  20. /**
  21. * @todo
  22. */
  23. function config($name) {
  24. if (isset($this->settings[$name])) {
  25. return $this->settings[$name];
  26. }
  27. if (!empty($this->delta->parent)) {
  28. if ($plugin = delta_get_plugin($this->delta->parent, $this->plugin['name'])) {
  29. $this->settings[$name] = isset($this->delta->settings[$name]) ? delta_merge($plugin->config($name), $this->delta->settings[$name]) : $plugin->config($name);
  30. }
  31. }
  32. if (!isset($this->settings[$name])) {
  33. $this->settings[$name] = isset($this->delta->settings[$name]) ? delta_merge(variable_get($name), $this->delta->settings[$name]) : variable_get($name);
  34. }
  35. return $this->settings[$name];
  36. }
  37. /**
  38. * @todo
  39. */
  40. function inject() {
  41. foreach ($this->variables() as $name) {
  42. $settings = $this->config($name);
  43. if (isset($settings)) {
  44. $this->backup($name, delta_variable_set($name, $settings));
  45. }
  46. }
  47. }
  48. /**
  49. * @todo
  50. */
  51. function revoke() {
  52. foreach ($this->variables() as $name) {
  53. delta_variable_set($name, $this->backup($name));
  54. }
  55. }
  56. /**
  57. * @todo
  58. */
  59. function backup($name, $value = NULL) {
  60. if (isset($value) && !isset($this->original[$name])) {
  61. $this->original[$name] = $value;
  62. }
  63. if (isset($this->original[$name])) {
  64. return $this->original[$name];
  65. }
  66. }
  67. /**
  68. * @todo
  69. */
  70. function presave($form, &$form_state) {
  71. if ($this->delta->mode == DELTA_PRESERVE) {
  72. $base = array();
  73. if (!empty($this->delta->parent)) {
  74. if ($plugin = delta_get_plugin($this->delta->parent, $this->plugin['name'])) {
  75. foreach ($this->variables() as $variable) {
  76. $base[$variable] = $plugin->config($variable);
  77. }
  78. }
  79. }
  80. foreach ($this->variables() as $variable) {
  81. if (isset($base[$variable])) {
  82. $this->delta->settings[$variable] = delta_reduce($this->delta->settings[$variable], $base[$variable]);
  83. }
  84. else {
  85. $this->delta->settings[$variable] = delta_reduce(
  86. is_array($this->delta->settings[$variable]) ? $this->delta->settings[$variable] : array(),
  87. is_array(variable_get($variable)) ? variable_get($variable) : array());
  88. }
  89. }
  90. }
  91. }
  92. /**
  93. * @todo
  94. */
  95. function form_alter(&$form, &$form_state) {
  96. // Nothing to do here.
  97. }
  98. /**
  99. * @todo
  100. */
  101. function form_validate($form, &$form_state) {
  102. foreach ($this->variables() as $name) {
  103. $this->backup($name, variable_get($name));
  104. }
  105. }
  106. /**
  107. * @todo
  108. */
  109. function form_submit($form, &$form_state) {
  110. foreach ($this->variables() as $name) {
  111. $this->delta->settings[$name] = variable_get($name);
  112. variable_set($name, $this->backup($name));
  113. }
  114. }
  115. }