You are here

function newsletter_field_attach_presave in Newsletter 7

Implements hook_field_attach_presave().

File

./newsletter.module, line 887
Defines menu items for newsletter administration, permissions and basic drupal hooks.

Code

function newsletter_field_attach_presave($entity_type, $entity) {
  if ($entity_type == 'newsletter_subscriber') {
    $exposed_lists = newsletter_exposed_lists();
    foreach ($exposed_lists as $exposed_list) {
      $terms = isset($entity->{'exposed_' . $exposed_list}) ? $entity->{'exposed_' . $exposed_list} : array();
      $tids = array();
      foreach ($terms as $tid => $value) {
        if (!empty($value)) {
          $tids[] = $tid;
        }
      }
      $tids = !empty($tids) ? serialize($tids) : NULL;
      $lang = field_language($entity_type, $entity, 'field_newsletter_list');
      foreach ($entity->field_newsletter_list[$lang] as $key => $list) {
        if ($list['target_id'] == $exposed_list) {
          $entity->field_newsletter_list[$lang][$key]['target_id_tids'] = $tids;
        }
      }
    }
  }
}