entityconnect.install 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. /**
  3. * @file
  4. * Install, update & uninstall functions for the Entity Connect module.
  5. */
  6. /**
  7. * Implements hook_requirements().
  8. */
  9. function entityconnect_requirements($phase) {
  10. $requirements = array();
  11. switch ($phase) {
  12. case 'install':
  13. $t = get_t();
  14. $path = drupal_get_path('module', 'entityconnect') . '/entityconnect.info';
  15. $info = drupal_parse_info_file($path);
  16. $requirements['entityconnect'] = array();
  17. $requirements['entityconnect']['title'] = $info['name'];
  18. $requirements['entityconnect']['value'] = $info['version'];
  19. // At least one of the following modules is required in order for
  20. // entityconnect to function properly.
  21. $singularly_required_modules = array(
  22. 'entityreference',
  23. 'node_reference',
  24. 'user_reference',
  25. );
  26. // If this module is being installed as part of a Drupal installation,
  27. // check for the existence of required modules without relying on the
  28. // "module_exists()" function, which will always return false for these
  29. // modules during a Drupal installation.
  30. if (drupal_installation_attempted()) {
  31. $files = drupal_system_listing('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\.info$/', 'modules', 'name', 0);
  32. foreach ($singularly_required_modules as $module_name) {
  33. if (isset($files[$module_name])) {
  34. $requirements['entityconnect']['severity'] = REQUIREMENT_OK;
  35. break;
  36. }
  37. }
  38. }
  39. // If this module is being installed manually (after Drupal has been
  40. // installed), check to ensure that one of the required modules exists
  41. // and is enabled.
  42. else {
  43. foreach ($singularly_required_modules as $module_name) {
  44. if (module_exists($module_name)) {
  45. $requirements['entityconnect']['severity'] = REQUIREMENT_OK;
  46. break;
  47. }
  48. }
  49. }
  50. if (!isset($requirements['entityconnect']['severity'])) {
  51. $requirements['entityconnect']['severity'] = REQUIREMENT_ERROR;
  52. $requirements['entityconnect']['description'] = $t(
  53. 'Neither Entityreference nor References module is installed or activated.
  54. Entityconnect needs at least one of those modules to work.'
  55. );
  56. }
  57. break;
  58. }
  59. return $requirements;
  60. }
  61. /**
  62. * Implements hook_schema().
  63. */
  64. function entityconnect_schema() {
  65. $schema = array();
  66. $schema['cache_entityconnect'] = drupal_get_schema_unprocessed('system', 'cache');
  67. return $schema;
  68. }
  69. /**
  70. * Implements hook_install().
  71. */
  72. function entityconnect_install() {
  73. // We need to run after the workbench_email module so that our
  74. // entityconnect_return redirect works properly.
  75. db_update('system')
  76. ->fields(array('weight' => 1))
  77. ->condition('name', 'entityconnect')
  78. ->condition('type', 'module')
  79. ->execute();
  80. }
  81. /**
  82. * Add cache table.
  83. */
  84. function entityconnect_update_7000() {
  85. if (!db_table_exists('cache_entityconnect')) {
  86. $schema = entityconnect_schema();
  87. db_create_table('cache_entityconnect', $schema ['cache_entityconnect']);
  88. }
  89. }
  90. /**
  91. * Change module weight so that other modules are less likely to break the
  92. * redirect that this module performs after creating a referenced entity.
  93. */
  94. function entityconnect_update_7101() {
  95. // We need to run after the workbench_email module so that our
  96. // entityconnect_return redirect works properly.
  97. db_update('system')
  98. ->fields(array('weight' => 1))
  99. ->condition('name', 'entityconnect')
  100. ->condition('type', 'module')
  101. ->execute();
  102. }
  103. /**
  104. * Update all settings from 7.x-1.x to 7.x-2.x
  105. */
  106. function entityconnect_update_7200() {
  107. $instances = field_info_instances();
  108. foreach ($instances as $entity_type => $bundles) {
  109. foreach ($bundles as $bundle_name => $fields) {
  110. if (!empty($fields)) {
  111. foreach ($fields as $field_name => $field) {
  112. if ($field['widget']['module'] == 'entityreference' || $field['widget']['module'] == 'node_reference' || $field['widget']['module'] == 'user_reference'
  113. || $field['display']['default']['module'] == 'entityreference' || $field['display']['default']['module'] == 'node_reference' || $field['display']['default']['module'] == 'user_reference') {
  114. $field['entityconnect']['button']['unload_add_button'] = $field['entityconnect_unload_add'];
  115. $field['entityconnect']['button']['unload_edit_button'] = $field['entityconnect_unload_edit'];
  116. $field['entityconnect']['icon']['show_add_icon'] = $field['entityconnect_show_add_icon'];
  117. $field['entityconnect']['icon']['show_edit_icon'] = $field['entityconnect_show_edit_icon'];
  118. field_update_instance($field);
  119. }
  120. }
  121. }
  122. }
  123. }
  124. }