| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
- /**
- * @file
- * Install, update & uninstall functions for the Entity Connect module.
- */
- /**
- * Implements hook_requirements().
- */
- function entityconnect_requirements($phase) {
- $requirements = array();
- switch ($phase) {
- case 'install':
- $t = get_t();
- $path = drupal_get_path('module', 'entityconnect') . '/entityconnect.info';
- $info = drupal_parse_info_file($path);
- $requirements['entityconnect'] = array();
- $requirements['entityconnect']['title'] = $info['name'];
- $requirements['entityconnect']['value'] = $info['version'];
- // At least one of the following modules is required in order for
- // entityconnect to function properly.
- $singularly_required_modules = array(
- 'entityreference',
- 'node_reference',
- 'user_reference',
- );
- // If this module is being installed as part of a Drupal installation,
- // check for the existence of required modules without relying on the
- // "module_exists()" function, which will always return false for these
- // modules during a Drupal installation.
- if (drupal_installation_attempted()) {
- $files = drupal_system_listing('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\.info$/', 'modules', 'name', 0);
- foreach ($singularly_required_modules as $module_name) {
- if (isset($files[$module_name])) {
- $requirements['entityconnect']['severity'] = REQUIREMENT_OK;
- break;
- }
- }
- }
- // If this module is being installed manually (after Drupal has been
- // installed), check to ensure that one of the required modules exists
- // and is enabled.
- else {
- foreach ($singularly_required_modules as $module_name) {
- if (module_exists($module_name)) {
- $requirements['entityconnect']['severity'] = REQUIREMENT_OK;
- break;
- }
- }
- }
- if (!isset($requirements['entityconnect']['severity'])) {
- $requirements['entityconnect']['severity'] = REQUIREMENT_ERROR;
- $requirements['entityconnect']['description'] = $t(
- 'Neither Entityreference nor References module is installed or activated.
- Entityconnect needs at least one of those modules to work.'
- );
- }
- break;
- }
- return $requirements;
- }
- /**
- * Implements hook_schema().
- */
- function entityconnect_schema() {
- $schema = array();
- $schema['cache_entityconnect'] = drupal_get_schema_unprocessed('system', 'cache');
- return $schema;
- }
- /**
- * Implements hook_install().
- */
- function entityconnect_install() {
- // We need to run after the workbench_email module so that our
- // entityconnect_return redirect works properly.
- db_update('system')
- ->fields(array('weight' => 1))
- ->condition('name', 'entityconnect')
- ->condition('type', 'module')
- ->execute();
- }
- /**
- * Add cache table.
- */
- function entityconnect_update_7000() {
- if (!db_table_exists('cache_entityconnect')) {
- $schema = entityconnect_schema();
- db_create_table('cache_entityconnect', $schema ['cache_entityconnect']);
- }
- }
- /**
- * Change module weight so that other modules are less likely to break the
- * redirect that this module performs after creating a referenced entity.
- */
- function entityconnect_update_7101() {
- // We need to run after the workbench_email module so that our
- // entityconnect_return redirect works properly.
- db_update('system')
- ->fields(array('weight' => 1))
- ->condition('name', 'entityconnect')
- ->condition('type', 'module')
- ->execute();
- }
- /**
- * Update all settings from 7.x-1.x to 7.x-2.x
- */
- function entityconnect_update_7200() {
- $instances = field_info_instances();
- foreach ($instances as $entity_type => $bundles) {
- foreach ($bundles as $bundle_name => $fields) {
- if (!empty($fields)) {
- foreach ($fields as $field_name => $field) {
- if ($field['widget']['module'] == 'entityreference' || $field['widget']['module'] == 'node_reference' || $field['widget']['module'] == 'user_reference'
- || $field['display']['default']['module'] == 'entityreference' || $field['display']['default']['module'] == 'node_reference' || $field['display']['default']['module'] == 'user_reference') {
- $field['entityconnect']['button']['unload_add_button'] = $field['entityconnect_unload_add'];
- $field['entityconnect']['button']['unload_edit_button'] = $field['entityconnect_unload_edit'];
- $field['entityconnect']['icon']['show_add_icon'] = $field['entityconnect_show_add_icon'];
- $field['entityconnect']['icon']['show_edit_icon'] = $field['entityconnect_show_edit_icon'];
- field_update_instance($field);
- }
- }
- }
- }
- }
- }
|