You are here

function party_get_data_set_info in Party 7

Same name and namespace in other branches
  1. 8.2 party.module \party_get_data_set_info()

Get all data sets from hook_party_data_set_info().

@todo: cache this, either in the DB or using DrupalCacheArray.

Parameters

$data_set_name: (optional) The name of the data set to return. If omitted, all are returned.

$reset: (optional) If set to true this will rebuild the data info, ignoring any cached version.

Return value

Either a single data set, or an array of data sets keyed by set name. Each set is an array whose keys are as returned by hook_party_data_set_info(), with in addition:

  • 'module': The module defining this set.
  • 'table': The table in which this set's data is stored.
55 calls to party_get_data_set_info()
PartyBaseTestCase::createTestProfile2 in tests/party.test
Create a test profile2 type and return the profile2 type machine name.
PartyController::getDataSetController in includes/party.entity.inc
Get the data set controller for a given entity and data set.
PartyDefaultDataSet::display in includes/party.data.inc
Return the renderable array for one of our attached entities.
PartyDefaultDataSet::getActions in includes/party.data.inc
Get actions for the attached entity. Check party access in each case.
PartyDefaultDataSet::getDataInfo in includes/party.data.inc
Get information from the data set or entity definition.

... See full list

File

./party.module, line 683
Provides a generic CRM party entity.

Code

function party_get_data_set_info($data_set_name = NULL, $reset = FALSE) {
  $sets =& drupal_static(__FUNCTION__);
  if (!isset($sets) || $reset) {
    if (($cache = cache_get('party:data_set_info', 'cache')) && !$reset) {
      $sets = $cache->data;
    }
    else {
      $sets = array();
      foreach (module_implements('party_data_set_info') as $module) {

        // Due to http://drupal.org/node/890660 we can't use module_invoke_all()
        // because we need to know the provenance of each set.
        $sets_module = module_invoke($module, 'party_data_set_info');
        foreach ($sets_module as $set_name => $set) {

          // Add in some essential data we need, but allow modules to set this too.
          if (isset($set['piece'])) {
            $path_element = $set['piece']['path'];
          }
          else {

            // @todo: fix this, as it's pretty weak and certainly in the case of
            // the user data set, relies on the piece happening to define its
            // path the same way.
            $path_element = str_replace('_', '-', $set_name);
          }
          $set += array(
            'set_name' => $set_name,
            'module' => $module,
            'singleton' => FALSE,
            'view mode' => 'party',
            'form callback' => 'party_default_attached_entity_form',
            // Singleton entities have no bundle; use the entity type.
            'entity bundle' => $set['entity type'],
            'path element' => $path_element,
          );

          // Translate 'singleton' to max cardinality of 1.
          // TODO: remove the singleton property? remove the cardinality
          // property? Which one actually gets used?
          if ($set['singleton']) {
            $set['max cardinality'] = 1;
          }
          $sets[$set_name] = $set;
        }
      }

      // Alter the data sets with hook_party_data_set_info_alter().
      drupal_alter('party_data_set_info', $sets);
      cache_set('party:data_set_info', $sets);
    }
  }
  if (isset($data_set_name)) {

    // @todo: Throw a big error if the $data_set_name doesn't exist
    return isset($sets[$data_set_name]) ? $sets[$data_set_name] : FALSE;
  }
  else {
    return $sets;
  }
}