You are here

protected static function PartyPrimaryFields::buildSources in Party 7

Build the primary field source information.

Parameters

bool $reset: Whether the cache should be reset.

1 call to PartyPrimaryFields::buildSources()
PartyPrimaryFields::getSources in includes/party.primary_fields.inc
Get hold of primary field source information.

File

includes/party.primary_fields.inc, line 715
Primary field related functions and callbacks.

Class

PartyPrimaryFields
Helper class for primary fields.

Code

protected static function buildSources($reset = FALSE) {

  // If we are resetting, clear our static cache.
  if ($reset) {
    self::$sources = NULL;
  }
  else {
    if ($cache = cache_get('party:primary_fields:sources')) {
      self::$sources = $cache->data;
    }
  }

  // If we have no information, build it.
  if (!isset(self::$sources)) {
    $field_map = field_info_field_map();
    self::$sources = array();

    // Go over our data sets finding potential sources.
    foreach (self::getDataSetInfo() as $data_set_name => $data_set) {

      // Build our data set information.
      self::$sources[$data_set_name] = array(
        'set_name' => $data_set['set_name'],
        'entity type' => $data_set['entity type'],
        'entity bundle' => $data_set['entity bundle'],
        'label' => $data_set['label'],
        'option label' => "{$data_set['label']} ({$data_set['set_name']})",
        'sources' => array(),
      );

      // Go over our property info to get the sources.
      $property_info = self::getPropertyInfo($data_set['entity type'], $data_set['entity bundle']);
      foreach ($property_info as $property => $info) {

        // Build our source info.
        $source_info = array(
          'label' => $info['label'],
          'option label' => "{$info['label']} ({$property})",
          'type' => isset($info['type']) ? $info['type'] : NULL,
          'field_type' => NULL,
          'data_set' => $data_set_name,
          'property' => $property,
          'value' => NULL,
          'callbacks' => array(),
          'all types' => array(),
        );

        // If this is a field we store the field type.
        if (!empty($info['field'])) {
          if (isset($field_map[$property])) {
            $source_info['field_type'] = $field_map[$property]['type'];
          }
        }

        // Get the key and add it to the data set sources.
        $key = self::getSourceKey($source_info);
        self::$sources[$data_set_name]['sources'][$key] = $source_info;

        // Process any values within this property.
        if (isset($info['property info'])) {
          foreach ($info['property info'] as $value => $value_info) {

            // Build our source info.
            $source_info = array(
              'label' => "{$info['label']}: {$value_info['label']}",
              'option label' => "{$info['label']}: {$value_info['label']} ({$property}:{$value})",
              'type' => isset($value_info['type']) ? $value_info['type'] : NULL,
              'field_type' => NULL,
              'data_set' => $data_set_name,
              'property' => $property,
              'value' => $value,
              'callbacks' => array(),
              'all types' => array(),
            );

            // Get the key and add it to the data set sources.
            $key = self::getSourceKey($source_info);
            self::$sources[$data_set_name]['sources'][$key] = $source_info;
          }
        }
      }
    }

    // Allow other modules to alter sources.
    drupal_alter('party_primary_fields_sources', self::$sources);

    // Run our cleanup.
    self::cleanSources(self::$sources);
  }

  // Store our information to the cache.
  cache_set('party:primary_fields:sources', self::$sources);
}