uo__unit.inc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. class uo__unit extends ChadoField {
  3. // The default lable for this field.
  4. public static $default_label = 'Unit';
  5. // The default description for this field.
  6. public static $description = 'The unit of measurement.';
  7. // Provide a list of instance specific settings. These can be access within
  8. // the instanceSettingsForm. When the instanceSettingsForm is submitted
  9. // then Drupal with automatically change these settings for the instnace.
  10. // It is recommended to put settings at the instance level whenever possible.
  11. // If you override this variable in a child class be sure to replicate the
  12. // term_name, term_vocab, term_accession and term_fixed keys as these are
  13. // required for all TripalFields.
  14. public static $default_instance_settings = array(
  15. // The short name for the vocabulary (e.g. shcema, SO, GO, PATO, etc.).
  16. 'term_vocabulary' => 'UO',
  17. // The name of the term.
  18. 'term_name' => 'unit',
  19. // The unique ID (i.e. accession) of the term.
  20. 'term_accession' => '0000000',
  21. // Set to TRUE if the site admin is allowed to change the term
  22. // type. This will create form elements when editing the field instance
  23. // to allow the site admin to change the term settings above.
  24. 'term_fixed' => FALSE,
  25. );
  26. // The default widget for this field.
  27. public static $default_widget = 'UO__unit_widget';
  28. // The default formatter for this field.
  29. public static $default_formatter = 'UO__unit_formatter';
  30. /**
  31. * @see TripalField::load()
  32. */
  33. public function load($entity) {
  34. $record = $entity->chado_record;
  35. $settings = $this->instance['settings'];
  36. $field_name = $this->field['field_name'];
  37. $field_type = $this->field['type'];
  38. $field_table = $this->instance['settings']['chado_table'];
  39. $field_column = $this->instance['settings']['chado_column'];
  40. // Set some defaults for the empty record.
  41. $entity->{$field_name}['und'][0] = array(
  42. 'value' => '',
  43. );
  44. if ($record) {
  45. $entity->{$field_name}['und'][0]['value'] = $record->unittype_id->name;
  46. }
  47. }
  48. }