function hook_tripal_default_title_format

3.x tripal.entities.api.inc hook_tripal_default_title_format($bundle, $available_tokens)

Implement this hook to define default formats for Tripal Content Types.

Parameters

TripalBundle $bundle: A tripal content type entity with information to be used for determining the default title format.

array $available_tokens: An array of available tokens for this particular tripal content type.

Return value

array An array of potential formats. The lightest weighted format suggested by all modules will be chosen. Each array item should consist of a 'weight' and 'format'. See the hook implementation below for examples.

  • weight: an integer used to determine priority of suggestions. The smaller/lighter the number the higher the priority. Best practice is to use a weight less than 0 for extension modules. specifically, -2 is a good weight for calculated formats and -5 is a good weight for hard-coded formats specific to a given type.
  • format: a string including approved tokens used to determine the title on Tripal content pages.

Related topics

1 function implements hook_tripal_default_title_format()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

tripal_chado_tripal_default_title_format in tripal_chado/includes/tripal_chado.entity.inc
Implements hook_tripal_default_title_format().
1 invocation of hook_tripal_default_title_format()
tripal_get_default_title_format in tripal/api/tripal.entities.api.inc
Determine the default title format to use for an entity.

File

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

Code

function hook_tripal_default_title_format($bundle, $available_tokens) {
  $format = array();

  // If you want to suggest a default format for a particular vocabulary term:
  //---------------------------------------------------------------------------
  // Load the term associated with this Tripal Content type.
  $term = entity_load('TripalTerm', array('id' => $bundle->term_id));
  $term = reset($term);

  // If it's the term you are interested in then suggest a format.
  if ($term->name == 'organism') {
    // To suggest a format, add an element to the array with a format & weight 
    // key.
    $format[] = array(
      // This is the format/pattern you suggest be used to determine the title 
      // of organism pages.
      'format' => '[organism__genus] [organism__species]',
      // The weight/priority of your suggestion.
      'weight' => -5
    );
  }

  // Say you know that in your particular site, all 'names' are required
  // and you want to only use the human-readable name:
  //---------------------------------------------------------------------------
  $name_field = preg_grep('/__name]$/', array_keys($available_tokens));
  $name_field = reset($name_field);
  if (is_string($name_field)) {
    $format[] = array(
      'format' => $name_field,
      'weight' => -2,
    );
  }

  return $format;
}