You are here

function commerce_customer_configure_customer_fields in Commerce Core 7

Configures fields referencing customer profile types defined by enabled modules and configures the fields on those profile types if necessary.

Parameters

$modules: An array of module names whose customer profile type fields should be configured; if left NULL, will default to all modules that implement hook_commerce_customer_profile_type_info().

1 call to commerce_customer_configure_customer_fields()
commerce_customer_modules_enabled in modules/customer/commerce_customer.module
Implements hook_modules_enabled().

File

modules/customer/commerce_customer.module, line 260
Defines the customer profile entity and API functions to manage customers and interact with them.

Code

function commerce_customer_configure_customer_fields($modules = NULL) {

  // If no modules array is passed, recheck the fields for all customer profile
  // types defined by enabled modules.
  if (empty($modules)) {
    $modules = module_implements('commerce_customer_profile_type_info');
  }

  // Reset the customer profile type static cache to ensure we get types added
  // by newly enabled modules.
  commerce_customer_profile_types_reset();

  // Loop through all the enabled modules.
  foreach ($modules as $module) {

    // If the module implements hook_commerce_customer_profile_type_info()...
    if (module_hook($module, 'commerce_customer_profile_type_info')) {
      $profile_types = module_invoke($module, 'commerce_customer_profile_type_info');

      // If this profile type has been previously disabled, update any reference
      // fields to be active again before attempting to recreate them.
      $activated = FALSE;
      foreach ($profile_types as $type => $profile_type) {
        foreach (field_read_fields(array(
          'type' => 'commerce_customer_profile_reference',
          'active' => 0,
          'storage_active' => 1,
          'deleted' => 0,
        ), array(
          'include_inactive' => TRUE,
        )) as $field_name => $field) {

          // If this field references profiles of the re-enabled type...
          if ($field['settings']['profile_type'] == $type) {
            if (commerce_activate_field($field_name)) {
              $activated = TRUE;
            }
          }
        }
      }

      // Clear the field cache if any profile reference fields were activated.
      if ($activated) {
        field_cache_clear();
      }

      // Loop through and configure the customer profile types defined by the module.
      foreach ($profile_types as $type => $profile_type) {

        // Default the addressfield property if it isn't set.
        $profile_type = array_merge(array(
          'addressfield' => TRUE,
        ), $profile_type);
        commerce_customer_configure_customer_profile_type($profile_type);
      }
    }
  }
}