uo__unit.inc 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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::validate()
  32. */
  33. public function validate($entity_type, $entity, $field, $items, &$errors) {
  34. }
  35. /**
  36. * @see TripalField::load()
  37. */
  38. public function load($entity, $details = array()) {
  39. $record = $details['record'];
  40. $settings = $this->instance['settings'];
  41. $field_name = $this->field['field_name'];
  42. $field_type = $this->field['type'];
  43. $field_table = $this->instance['settings']['chado_table'];
  44. $field_column = $this->instance['settings']['chado_column'];
  45. // Set some defaults for the empty record.
  46. $entity->{$field_name}['und'][0] = array(
  47. 'value' => '',
  48. );
  49. if ($record) {
  50. $entity->{$field_name}['und'][0]['value'] = $record->unittype_id->name;
  51. }
  52. }
  53. }