public function local__contact::load

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

Overrides TripalField::load

See also

TripalField::load()

File

tripal_chado/includes/TripalFields/local__contact/local__contact.inc, line 117

Class

local__contact

Code

public function load($entity) {
  $record = $entity->chado_record;

  $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'];
  $base_table = $this->instance['settings']['base_table'];

  $type_term = chado_get_semweb_term('contact', 'type_id');
  $name_term = chado_get_semweb_term('contact', 'name');
  $description_term = chado_get_semweb_term('contact', 'description');


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

  // Handle the biomaterial table.
  if ($field_table == 'biomaterial') {
    if ($record) {
      $contact = $record->biosourceprovider_id;
      if ($contact) {
        $entity->{$field_name}['und'][0] = array(
          'value' => array(
            $type_term => $contact->type_id ? $contact->type_id->name : '',
            $name_term => $contact->name,
            $description_term => $contact->description,
          ),
          $entity->{$field_name}['und'][0]['chado-biomaterial__biosourceprovider_id'] = $contact->contact_id,
        );
        if (property_exists($contact, 'entity_id')) {
          $entity->{$field_name}['und'][0]['value']['entity'] = 'TripalEntity:' . $contact->entity_id;
        }
      }
    }
  }
  // Here place other non-linker tables that have a FK to the contact table.
}