operation__phylotree_vis.inc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. class operation__phylotree_vis extends ChadoField {
  3. // The default label for this field.
  4. public static $default_label = 'Phylogenetic tree visualisation';
  5. // The default description for this field.
  6. public static $description = 'Rendering of a phylogenetic tree.';
  7. // Provide a list of instance specific settings. These can be accessed within
  8. // the instanceSettingsForm. When the instanceSettingsForm is submitted
  9. // then Drupal will automatically change these settings for the instance.
  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 = [
  15. // The short name for the vocabulary (e.g. schema, SO, GO, PATO, etc.).
  16. 'term_vocabulary' => 'operation',
  17. // The name of the term.
  18. 'term_name' => 'Phylogenetic tree visualisation',
  19. // The unique ID (i.e. accession) of the term.
  20. 'term_accession' => '0567',
  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 = 'operation__phylotree_vis_widget';
  28. // The default formatter for this field.
  29. public static $default_formatter = 'operation__phylotree_vis_formatter';
  30. /**
  31. * @see TripalField::validate()
  32. */
  33. public function validate($entity_type, $entity, $langcode, $items, &$errors) {
  34. // If we don't have an entity then we don't want to validate. The case
  35. // where this could happen is when a user is editing the field settings
  36. // and trying to set a default value. In that case there's no entity and
  37. // we don't want to validate. There will always be an entity for creation
  38. // and update operations of a content type.
  39. if (!$entity) {
  40. return;
  41. }
  42. $settings = $this->field['settings'];
  43. $field_name = $this->field['field_name'];
  44. $field_type = $this->field['type'];
  45. $field_table = $this->instance['settings']['chado_table'];
  46. $field_column = $this->instance['settings']['chado_column'];
  47. }
  48. /**
  49. * @see TripalField::load()
  50. */
  51. public function load($entity) {
  52. $record = $entity->chado_record;
  53. $settings = $this->instance['settings'];
  54. $field_name = $this->field['field_name'];
  55. $field_type = $this->field['type'];
  56. $field_table = $this->instance['settings']['chado_table'];
  57. $field_column = $this->instance['settings']['chado_column'];
  58. // Get the terms for each of the keys for the 'values' property.
  59. $label_term = 'operation:0567';
  60. // Set some defaults for the empty record.
  61. $entity->{$field_name}['und'][0]['value'] = [];
  62. if ($record) {
  63. $entity->{$field_name}['und'][0]['value'] = [
  64. 'schema:url' => url('bio_data/' . $entity->id, ['absolute' => TRUE]),
  65. ];
  66. }
  67. }
  68. /**
  69. * @see TripalField::elementInfo()
  70. */
  71. public function elementInfo() {
  72. $field_term = $this->getFieldTermID();
  73. return [
  74. $field_term => [
  75. 'operations' => [],
  76. 'sortable' => FALSE,
  77. 'searchable' => FALSE,
  78. 'type' => 'string',
  79. 'type' => 'xs:complexType',
  80. 'readonly' => TRUE,
  81. 'elements' => [
  82. 'schema:url' => [
  83. 'searchabel' => FALSE,
  84. 'type' => 'xs:anyURI',
  85. 'readonly' => TRUE,
  86. 'required' => FALSE,
  87. ],
  88. ],
  89. ],
  90. ];
  91. }
  92. }