public function TripalField::elementInfo

3.x TripalField.inc public TripalField::elementInfo()

Provides the list of elements returned by the 'value' of the field.

The elements provided by this function are used to integrate with Drupal Views and Web services. The return value is an associative array that contains all of the elements that will be returned by the 'value' of this field. If the value field returns an element which is not defined here a warning will be generated.

The array structure should contain at the top-level a key of the form {db}:{accession}. This represents the term that this field belongs to. The value of this top-level key is an array with the following keys: -name: this key is not actually used but is availble to improve readability of the array. Because the key is a vocabulary term conaining only the accession it's not always clear what it means. Providing a 'name' key helps other's know what the term is. -searchable: TRUE if the element can be used for filtering the content type to which tis field is attached. FALSE if not. -operations: an array of filtering operations that can be used for this field. These include: 'eq', 'ne', 'contains', 'starts', 'gt', 'lt', 'gte', 'lte'. These opertaions are applicable to strings: 'eq', 'ne', 'contains', and 'starts'. These operations are applicable for numeric values: 'gt', 'lt', 'gte', 'lte'. -label: The label (if applicable) to appear for the elmeent. The default is to use the term's name. -help: Help text (if applicable) to appear for the element. The default is to use the term's definition. -type: The data type: e.g. 'string' or 'numeric'. Default is 'string'. -sortable: TRUE if the element can be sorted. FALSE if not. -elements: If this field value is a simple scalar (i.e. string or number) then this key is not needed. But, if the 'value' of the field is an array with sub keys then those subkeys must be defined using this key. The members of the element array follows the same format as the top-level key and the above subkeys can be used as well.

The following code provides an example for describing the value elements of this field. The Tripal Chado module provides an obi__organism field that attaches organism details to content types such as genes, mRNA, stocks, etc. It provides a label containing the full scientific name of the organism as well as the genus, species, infraspecific name, and infraspecific type. If the organism to which the field belong is published then an entity ID is provided. The following array describes all of these.

   $field_term = $this->getFieldTermID();
   return array(
     $field_term => array(
       'operations' => array('eq', 'contains', 'starts'),
       'sortable' => TRUE,
       'searchable' => TRUE,
       'elements' => array(
         'rdfs:label' => array(
           'searchable' => TRUE,
           'name' => 'scientific_name',
           'operations' => array('eq', 'ne', 'contains', 'starts'),
           'sortable' => TRUE,
         ),
         'TAXRANK:0000005' => array(
           'searchable' => TRUE,
           'name' => 'genus',
           'operations' => array('eq', 'ne', 'contains', 'starts'),
           'sortable' => TRUE,
         ),
         'TAXRANK:0000006' => array(
           'searchable' => TRUE,
           'name' => 'species',
           'operations' => array('eq', 'ne', 'contains', 'starts'),
           'sortable' => TRUE,
         ),
         'TAXRANK:0000045' => array(
           'searchable' => TRUE,
           'name' => 'infraspecies',
           'operations' => array('eq', 'ne', 'contains', 'starts'),
           'sortable' => TRUE,
         ),
         'local:infraspecific_type' => array(
           'searchable' => TRUE,
           'name' => 'infraspecific_type',
           'operations' => array('eq', 'ne', 'contains', 'starts'),
           'sortable' => TRUE,
         ),
         'entity' => array(
           'searchable' => FALSE,
         ),
       ),
     )
   );

If a field does not have a complex nested set of values, but simply returns a scalar then the default elementInfo provides default string-based searchabilty.

Return value

An associative array of the value elements provided by this field.

2 calls to TripalField::elementInfo()
TripalField::viewsData in tripal/includes/TripalFields/TripalField.inc
Describes this field to Views.
TripalField::webServicesData in tripal/includes/TripalFields/TripalField.inc
Describes this field to Tripal web services.
22 methods override TripalField::elementInfo()
chado_linker__contact::elementInfo in tripal_chado/includes/TripalFields/chado_linker__contact/chado_linker__contact.inc
data__protein_sequence::elementInfo in tripal_chado/includes/TripalFields/data__protein_sequence/data__protein_sequence.inc
data__sequence::elementInfo in tripal_chado/includes/TripalFields/data__sequence/data__sequence.inc
data__sequence_checksum::elementInfo in tripal_chado/includes/TripalFields/data__sequence_checksum/data__sequence_checksum.inc
data__sequence_coordinates::elementInfo in tripal_chado/includes/TripalFields/data__sequence_coordinates/data__sequence_coordinates.inc

... See full list

File

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

Class

TripalField

Code

public function elementInfo() {
  $field_term = $this->getFieldTermID();
  return array(
    $field_term => array(
      'operations' => array('eq', 'ne', 'contains', 'starts'),
      'sortable' => TRUE,
      'searchable' => TRUE,
    ),
  );
}