public function taxrank__infraspecific_taxon::load

3.x taxrank__infraspecific_taxon.inc public taxrank__infraspecific_taxon::load($entity)

Overrides TripalField::load

See also

TripalField::load()

File

tripal_chado/includes/TripalFields/taxrank__infraspecific_taxon/taxrank__infraspecific_taxon.inc, line 157

Class

taxrank__infraspecific_taxon

Code

public function load($entity) {
  $record = $entity->chado_record;
  $settings = $this->field['settings'];

  $field_name = $this->field['field_name'];
  $field_type = $this->field['type'];
  $field_table = $this->instance['settings']['chado_table'];
  $field_column = $this->instance['settings']['chado_column'];

  $entity->{$field_name}['und'][0]['value'] = '';

  if (chado_get_version() < 1.3) {
    return;
  }

  $label_term = 'rdfs:label';
  $infraspecific_name_term = chado_get_semweb_term('organism', 'infraspecific_name');
  $infraspecific_type_term = chado_get_semweb_term('organism', 'type_id');

  // Set some defaults for the empty record.
  $entity->{$field_name}['und'][0] = array(
    'value' => array(),
    'chado-organism__infraspecific_name' => '',
    'chado-organism__type_id' => '',
  );

  if ($record->infraspecific_name) {
    $label = $record->type_id->name . ' ' . $record->infraspecific_name;
    $entity->{$field_name}['und'][0]['value'][$label_term] = $label;
    $entity->{$field_name}['und'][0]['value'][$infraspecific_name_term] = $record->infraspecific_name;
    $entity->{$field_name}['und'][0]['chado-organism__infraspecific_name'] = $record->infraspecific_name;
  }

  if ($record->type_id) {
    $entity->{$field_name}['und'][0]['value'][$infraspecific_type_term] = $record->type_id->name;
    $entity->{$field_name}['und'][0]['chado-organism__type_id'] = $record->type_id->cvterm_id;
  }
}