You are here

function party_get_email_fields in Party 8.2

Get all the email fields set up on data set entities

@todo:

  • Drupal Cache
  • Put in a standard party_mail api.

Parameters

$data_set_name If this is set, the function will return a list of: email fields on that data set.

3 calls to party_get_email_fields()
party_get_all_emails in modules/party_simplenews/party_simplenews.module
Get all the emails on a Party
party_simplenews_entity_update in modules/party_simplenews/party_simplenews.module
Implements hook_entity_update.
party_simplenews_simplenews_subscriber_insert in modules/party_simplenews/party_simplenews.module
Implements hook_simplenews_subscriber_insert.

File

modules/party_simplenews/party_simplenews.module, line 411
Main module file for Party Simplenews integration

Code

function party_get_email_fields($data_set_name = NULL) {
  $email_fields =& drupal_static(__FUNCTION__, array());

  // If we have a cached set of fields, return this.
  if (!empty($email_fields)) {
    if (!empty($data_set_name)) {
      return empty($email_fields[$data_set_name]) ? array() : $email_fields[$data_set_name];
    }
    return $email_fields;
  }
  $fields = field_info_fields();
  $data_sets = party_get_data_set_info();
  foreach ($fields as $field_name => $field) {

    // Is it an email field?
    if ($field['type'] != 'email') {
      continue;
    }

    // Is it on an attached entity?
    foreach ($field['bundles'] as $entity_type => $bundles) {
      foreach ($bundles as $bundle) {
        foreach ($data_sets as $name => $def) {
          if ($def['entity type'] == $entity_type && $def['entity bundle'] == $bundle) {

            // Put it in an array keyed by data set name and field name
            $email_fields[$name][] = $field_name;
          }
        }
      }
    }
  }
  if (!empty($data_set_name)) {
    return empty($email_fields[$data_set_name]) ? array() : $email_fields[$data_set_name];
  }
  return $email_fields;
}