function tripal_get_entity_tokens

3.x tripal.entities.api.inc tripal_get_entity_tokens($entity, $options = array())

Returns an array of tokens based on Tripal Entity Fields.

Parameters

TripalBundle $entity: The bundle entity for which you want tokens.

Return value

An array of tokens where the key is the machine_name of the token.

Related topics

3 calls to tripal_get_entity_tokens()
remote__data::instanceSettingsForm in tripal_ws/includes/TripalFields/remote__data/remote__data.inc
tripal_get_default_title_format in tripal/api/tripal.entities.api.inc
Determine the default title format to use for an entity.
tripal_tripal_bundle_form in tripal/includes/TripalBundleUIController.inc
Tripal content type edit form.

File

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

Code

function tripal_get_entity_tokens($entity, $options = array()) {
  $tokens = array();

  // Set default options.
  $options['required only'] = (isset($options['required only'])) ? $options['required only'] : FALSE;
  $options['include id'] = (isset($options['include id'])) ? $options['include id'] : TRUE;

  if ($options['include id']) {
    $token = '[TripalBundle__bundle_id]';
    $tokens[$token] = array(
      'label' => 'Bundle ID',
      'description' => 'The unique identifier for this Tripal Content Type.',
      'token' => $token,
      'field_name' => NULL,
      'required' => TRUE
    );

    $token = '[TripalEntity__entity_id]';
    $tokens[$token] = array(
      'label' => 'Content/Entity ID',
      'description' => 'The unique identifier for an individual piece of Tripal Content.',
      'token' => $token,
      'field_name' => NULL,
      'required' => TRUE
    );
  }

  $fields = field_info_instances('TripalEntity', $entity->name);
  foreach ($fields as $f) {

    // Build the token from the field information.
    $token = '[' . $f['field_name'] . ']';
    $current_token = array(
      'label' => $f['label'],
      'description' => $f['description'],
      'token' => $token,
      'field_name' => $f['field_name'],
      'required' => $f['required']
    );

    // If the required only option is set then we only want to add
    // required fields to the token list.
    if ($options['required only'] AND $current_token['required']) {
      $tokens[$token] = $current_token;
    }
    // If the required only option is not set then add everything.
    elseif (!$options['required only']) {
      $tokens[$token] = $current_token;
    }
  }

  return $tokens;
}