public function TripalField::__construct

3.x TripalField.inc public TripalField::__construct($field, $instance)

Instantiates a new TripalField object.

Parameters

$field: An array containing the field data as returned by field_info_field().

$instance: An array containing the instance data as returned by field_instance_info().

1 call to TripalField::__construct()
remote__data::__construct in tripal_ws/includes/TripalFields/remote__data/remote__data.inc
Instantiates a new TripalField object.
1 method overrides TripalField::__construct()
remote__data::__construct in tripal_ws/includes/TripalFields/remote__data/remote__data.inc
Instantiates a new TripalField object.

File

tripal/includes/TripalFields/TripalField.inc, line 120

Class

TripalField

Code

public function __construct($field, $instance) {
  $term = NULL;
  $vocabulary = NULL;
  $accession = NULL;
  $this->field = $field;
  $this->instance = $instance;

  $class = get_called_class();

  // Use the term info defined in the class by default (assuming it's not schema:Thing ;-).
  if ($class::$default_instance_settings['term_name'] != 'Thing') {
    $vocabulary = $class::$default_instance_settings['term_vocabulary'];
    $accession = $class::$default_instance_settings['term_accession'];
  }

  // Allow the constructor to override the term info.
  $vocabulary = isset($this->instance['settings']['term_vocabulary']) ? $this->instance['settings']['term_vocabulary'] : $vocabulary;
  $accession = isset($this->instance['settings']['term_accession']) ? $this->instance['settings']['term_accession'] : $accession;

  // Assuming we have term info, load the term.
  if (!empty($vocabulary) AND !empty($accession)) {
    $this->term = tripal_get_term_details($vocabulary, $accession);
  }
  else {
    $bundle = tripal_load_bundle_entity(array('name' => $instance['bundle']));
    tripal_report_error('tripal_field', TRIPAL_ERROR, 
    'Unable to instantiate the field named, ":name", due to missing vocabulary and/or accession. The term provided was: ":term". The bundle is: ":bundle".', 
    array(':name' => $instance['field_name'],
      ':term' => $vocabulary . ':' . $accession,
      ':bundle' => $bundle->label));
  }
  if (!$instance) {
    tripal_set_message(t('Missing instance of field "%field"', array('%field' => $field['field_name'])), TRIPAL_ERROR);
  }
}