function tripal_get_default_title_format

3.x tripal.entities.api.inc tripal_get_default_title_format($bundle)

Determine the default title format to use for an entity.

Parameters

TripalBundle $bundle: The Entity object for the Tripal Bundle that the title format is for.

Return value

string A default title format.

Related topics

1 call to tripal_get_default_title_format()
tripal_get_title_format in tripal/api/tripal.entities.api.inc
Get Page Title Format for a given Tripal Entity Type.

File

tripal/api/tripal.entities.api.inc, line 959
Provides an application programming interface (API) for working with TripalEntity content types (bundles) and their entities.

Code

function tripal_get_default_title_format($bundle) {
  $format = '';

  // Retrieve all available tokens.
  $tokens = tripal_get_entity_tokens($bundle);

  // A) Check to see if more informed modules have suggested a title for this
  //    type. Invoke hook_tripal_default_title_format() to get all suggestions
  //    from other modules.
  $suggestions = module_invoke_all('tripal_default_title_format', $bundle, $tokens);
  if ($suggestions) {
    // Use the suggestion with the lightest weight.
    $lightest_key = NULL;
    foreach ($suggestions as $k => $s) {
      if ($lightest_key === NULL) {
        $lightest_key = $k;
      }
      if ($s['weight'] < $lightest_key) {
        $lightest_key = $k;
      }
    }
    $format = $suggestions[$lightest_key]['format'];
    return $format;
  }

  // B) Generate our own ugly title by simply comma-separating all the
  //    required fields.
  if (!$format) {
    $tmp = array();

    // Check which tokens are required fields and join them into a default 
    // format.
    foreach ($tokens as $token) {
      if ($token['required']) {
        $tmp[] = $token['token'];
      }
    }
    $format = implode(', ', $tmp);
    return $format;
  }

  return $format;
}