You are here

function _entityreference_autofill_get_settings in Entity reference autofill 7

Get settings for fields that have autofill enabled.

Parameters

bool $reset: Boolean indicating if the settings should be generated or fetched from cache.

Return value

array Multidimensional map of entityreference fields, keyed by (in order) entity type, bundle and field name. A settings entry contains:

  • overwrite: Boolean indicating if fields with values should be overwritten.
  • prepopulate: Available if the Entityreference prepopulate module is enabled for this field.
  • fields: Map of fields that should be filled by the module.
3 calls to _entityreference_autofill_get_settings()
entityreference_autofill_field_attach_form in ./entityreference_autofill.module
Implements hook_field_attach_form().
entityreference_autofill_field_update_instance in ./entityreference_autofill.module
Implements hook_field_update_instance().
entityreference_autofill_update_7001 in ./entityreference_autofill.install
Move widget settings to behavior class settings.

File

./entityreference_autofill.module, line 500
Entity reference autofill module.

Code

function _entityreference_autofill_get_settings($reset = FALSE) {

  // Use cached if available
  // (Static is superfluous for now).
  $settings =& drupal_static(__FUNCTION__);
  if (!isset($settings) && !$reset) {
    $cache = cache_get(__FUNCTION__);
    if (!empty($cache->data)) {
      $settings = $cache->data;
    }
  }

  // Rebuild settings.
  if (!isset($settings) || $reset) {
    $field_map = field_info_field_map();
    $enabled_fields = array();
    foreach ($field_map as $field_name => $field) {
      if ($field['type'] !== 'entityreference') {
        continue;
      }
      foreach ($field['bundles'] as $entity_type => $bundles) {
        foreach ($bundles as $bundle) {
          $field_info = field_info_instance($entity_type, $field_name, $bundle);
          if (isset($field_info['settings']['behaviors']['autofill'])) {
            $module_settings = $field_info['settings']['behaviors']['autofill'];
            if ($module_settings['status']) {

              // Clear unused fields from field array.
              $module_settings['fields'] = array_filter($module_settings['fields']);
              $enabled_fields[$entity_type][$bundle][$field_name] = $module_settings;

              // Reduntant, module is enabled if key exists.
              unset($module_settings['status']);

              // Entityreference prepopulate is enabled.
              if (!empty($field_info['settings']['behaviors']['prepopulate']['status'])) {
                $enabled_fields[$entity_type][$bundle][$field_name]['prepopulate'] = TRUE;
              }
            }
          }
        }
      }
    }
    cache_set(__FUNCTION__, $enabled_fields);
    $settings = $enabled_fields;
  }
  return $settings;
}