You are here

function mailchimp_lists_update_7002 in Mailchimp 7.4

Same name and namespace in other branches
  1. 7.5 modules/mailchimp_lists/mailchimp_lists.install \mailchimp_lists_update_7002()
  2. 7.3 modules/mailchimp_lists/mailchimp_lists.install \mailchimp_lists_update_7002()

Convert Mailchimp merge field placeholders to proper token syntax.

File

modules/mailchimp_lists/mailchimp_lists.install, line 42
Install, update and uninstall functions for the mailchimp_lists module.

Code

function mailchimp_lists_update_7002(&$sandbox) {
  $fields = field_info_fields();
  $instances = field_info_instances();

  // Loop over all configured instances of mailchimp_lists_subscription type
  // fields, and update their mergefields settings to use the new token syntax.
  foreach ($instances as $entity_type => $bundles) {
    foreach ($bundles as $field_instances) {
      foreach ($field_instances as $field_instance) {
        if ($fields[$field_instance['field_name']]['type'] == 'mailchimp_lists_subscription' && isset($field_instance['settings']['mergefields'])) {
          foreach ($field_instance['settings']['mergefields'] as $key => $value) {
            if (!empty($value)) {

              // Convert to token syntax like [user:mail].
              $value = str_replace('_', '-', $value);
              $field_instance['settings']['mergefields'][$key] = '[' . $entity_type . ':' . $value . ']';
            }
          }

          // Save any changes to the field instance.
          field_update_instance($field_instance);
        }
      }
    }
  }
}