You are here

mvf.install in Measured Value Field 7

Same filename and directory in other branches
  1. 6 mvf.install

Install, update, and uninstall functions for the Measured Value Field module.

File

mvf.install
View source
<?php

/**
 * @file
 * Install, update, and uninstall functions for the Measured Value Field module.
 */

/**
 * Implements hook_field_schema().
 */
function mvf_field_schema($field) {
  module_load_include('module', 'mvf');
  module_load_install(MVF_MODULE_UNIT);
  module_load_install(MVF_MODULE_VALUE);
  $schema = array();

  // Delegating field schema generation down to subfields and merging the output
  // into a single return array.
  foreach (array(
    'value',
    'unit',
  ) as $subfield) {
    $mocked_filed = mvf_field_mockup($field, $subfield);
    $schema = array_merge_recursive($schema, module_invoke($mocked_filed['module'], 'field_schema', $mocked_filed));
  }
  return $schema;
}

/**
 * Adjust settings of MVF fields to the format of a new version.
 */
function mvf_update_7101() {

  // We need info about units_unit entity type.
  $units_entity_info = entity_get_info('units_unit');
  $mvf_field_types = array_keys(module_invoke('mvf', 'field_info'));
  foreach (field_info_field_map() as $field_name => $field_info) {
    if (in_array($field_info['type'], $mvf_field_types)) {
      $field_info = field_info_field($field_name);
      foreach ($field_info['bundles'] as $entity_type => $bundles) {
        foreach ($bundles as $bundle) {
          $instance = field_info_instance($entity_type, $field_name, $bundle);
          $instance['widget']['settings']['meta_info']['unit']['label_property'] = $units_entity_info['entity keys']['label'];
          field_update_instance($instance);
        }
      }
    }
  }
}

/**
 * Update settings of MVF instances.
 */
function mvf_update_7102() {
  $mvf_field_types = array_keys(module_invoke('mvf', 'field_info'));
  foreach (field_info_field_map() as $field_name => $field_info) {
    if (in_array($field_info['type'], $mvf_field_types)) {
      $field_info = field_info_field($field_name);
      foreach ($field_info['bundles'] as $entity_type => $bundles) {
        foreach ($bundles as $bundle) {
          $instance = field_info_instance($entity_type, $field_name, $bundle);
          $map = array(
            'MVFUnitSuggesterHardCoded' => 'hardcoded',
            'MVFUnitSuggesterLocale' => 'locale',
            'MVFUnitSuggesterOriginal' => 'original',
            'MVFPerUserUnitSuggesterUser' => 'per_user',
          );
          $instance['settings']['mvf']['unit_suggesters_settings'] = isset($instance['display']['default']['settings']['mvf']['unit_suggester_settings']) ? $instance['display']['default']['settings']['mvf']['unit_suggester_settings'] : array();
          foreach ($instance['settings']['mvf']['unit_suggesters_settings'] as $k => $v) {
            unset($instance['settings']['mvf']['unit_suggesters_settings'][$k]);
            if (isset($map[$k])) {
              $instance['settings']['mvf']['unit_suggesters_settings'][$map[$k]] = $v;
            }
          }
          foreach ($instance['display'] as $view_mode => $display) {
            $display['settings']['mvf']['override'] = FALSE;
            unset($display['settings']['mvf']['unit_suggester_settings']);
            $instance['display'][$view_mode] = $display;
          }
          field_update_instance($instance);
        }
      }
    }
  }
}

Functions

Namesort descending Description
mvf_field_schema Implements hook_field_schema().
mvf_update_7101 Adjust settings of MVF fields to the format of a new version.
mvf_update_7102 Update settings of MVF instances.