You are here

entityconnect.install in Entity connect 7.2

Same filename and directory in other branches
  1. 8.2 entityconnect.install
  2. 7 entityconnect.install

Install, update & uninstall functions for the Entity Connect module.

File

entityconnect.install
View source
<?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;
          }
        }
      }
      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);
          }
        }
      }
    }
  }
}

Functions

Namesort descending Description
entityconnect_install Implements hook_install().
entityconnect_requirements Implements hook_requirements().
entityconnect_schema Implements hook_schema().
entityconnect_update_7000 Add cache table.
entityconnect_update_7101 Change module weight so that other modules are less likely to break the redirect that this module performs after creating a referenced entity.
entityconnect_update_7200 Update all settings from 7.x-1.x to 7.x-2.x