Tripal
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
TripalField Class Reference
Inheritance diagram for TripalField:
Inheritance graph
[legend]

Public Member Functions

 __construct ($field, $instance)
 
 getFieldName ()
 
 getField ()
 
 getInstance ()
 
 getFieldTerm ()
 
 getFieldTermID ()
 
 webServicesData ()
 
 viewsData ($view_base_id)
 
 validate ($entity_type, $entity, $langcode, $items, &$errors)
 
 load ($entity)
 
 elementInfo ()
 
 settingsForm ($has_data)
 
 settingsFormValidate ($form, &$form_state)
 
 instanceSettingsForm ()
 
 settingsTheme ($element)
 
 instanceSettingsFormValidate ($form, &$form_state)
 
 createInstance ()
 
 query ($query, $condition)
 
 queryOrder ($query, $order)
 
 getValueList ($options=[], $keyword=NULL)
 

Static Public Member Functions

static info ()
 

Static Public Attributes

static $default_label = 'Tripal Field'
 
static $default_description = 'The generic base class for all Tripal fields. Replace this text as appropriate for the child implementation.'
 
static $default_settings
 
static $default_instance_settings
 
static $download_formatters
 
static $default_widget = ''
 
static $default_formatter = ''
 
static $module = 'tripal'
 
static $no_ui = TRUE
 
static $no_data = FALSE
 

Protected Member Functions

 _addWebServiceElement (&$searchable_keys, &$sortable_keys, $parent_term_name, $parent_term, $element_name, $element_details)
 
 _addViewsDataElement (&$data, $view_base_id, $parent, $element_name, $element_details)
 

Protected Attributes

 $field
 
 $instance
 
 $term
 

Constructor & Destructor Documentation

◆ __construct()

TripalField::__construct (   $field,
  $instance 
)

Instantiates a new TripalField object.

Parameters
$fieldAn array containing the field data as returned by field_info_field().
$instanceAn array containing the instance data as returned by field_instance_info().

Reimplemented in remote__data, and sbo__relationship.

Member Function Documentation

◆ _addViewsDataElement()

TripalField::_addViewsDataElement ( $data,
  $view_base_id,
  $parent,
  $element_name,
  $element_details 
)
protected
Parameters
unknown$data
unknown$view_base_id
unknown$parent
unknown$element_name
unknown$element_details

◆ _addWebServiceElement()

TripalField::_addWebServiceElement ( $searchable_keys,
$sortable_keys,
  $parent_term_name,
  $parent_term,
  $element_name,
  $element_details 
)
protected
Parameters
$searchabe_keys
$field_name
$element_name
$element_details

◆ createInstance()

TripalField::createInstance ( )

After a field instance is created the following function is run.

This function is equivalent to the hook_field_create_field() hook of the Drupal Field API. This function is invoked after a new field instance is created.

◆ elementInfo()

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 containing 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.

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

Reimplemented in taxrank__infraspecific_taxon, so__transcript, so__genotype, so__cds, sio__references, sio__annotation, sep__protocol, schema__publication, sbo__relationship, sbo__phenotype, sbo__database_cross_reference, operation__phylotree_vis, operation__analysis, ogi__location_on_map, obi__organism, local__source_data, local__contact, go__gene_expression, efo__array_design, data__sequence_record, data__sequence_length, data__sequence_coordinates, data__sequence_checksum, data__sequence, data__protein_sequence, and chado_linker__contact.

◆ getFieldName()

TripalField::getFieldName ( )

Retrives the name of this field.

Returns
This field's name.

◆ getValueList()

TripalField::getValueList (   $options = [],
  $keyword = NULL 
)

Used to retrieve a distinct list of values already used for the current field instance.

Parameters
$keywordA string option used to filter the distinct list. This is used when creating an autocomplete. For all distinct values, set this to NULL.
$optionsAn array where options for how to generate this list can be specified. Supported options include:
  • limit: how many results to limit to (Default: 25)
  • label_string: a string with tokens that should be used to generate the human-readable values in the returned list.
Returns
An array of values.

Reimplemented in ChadoField.

◆ info()

static TripalField::info ( )
static

Provides default information about this field type

This function corresponds to the hook_field_info() function of the Drupal Field API.

Returns
An array whose keys are field type names and whose values are arrays describing the field type. The keys are the same as for the hook_field_info() function.

◆ instanceSettingsForm()

TripalField::instanceSettingsForm ( )

Provides a form for the 'Field Settings' of an instance of this field.

This function corresponds to the hook_field_instance_settings_form() function of the Drupal Field API.

Validation of the instance settings form is not supported by Drupal, but the TripalField class does provide a mechanism for supporting validation. To allow for validation of your setting form you must call the parent in your child class:

$element = parent::instanceSettingsForm();

Additinally, theming of the instance setting form is not supported by Drupal, but Tripal will allow you to theme form elements if you place them in the $element['themeable'] variable. However, if you place form elements there you must set corresponding form elements of type 'value' at the base level of the element array and copy appropriate settings values from the $form_state['values']['instance']['settings']['themeable'] variable into the $form_state['values']['instance']['settings'] variable. Do this in the instanceSettingsFormValidate() function.

Please note, the form generated with this function does not easily support AJAX calls in the same way that other Drupal forms do. If you need to use AJAX you must manually alter the $form in your ajax call. The typical way to handle updating the form via an AJAX call is to make the changes in the form function itself but that doesn't work here.

Reimplemented in remote__data, so__transcript, schema__additional_type, sbo__relationship, obi__organism, and ChadoField.

◆ instanceSettingsFormValidate()

TripalField::instanceSettingsFormValidate (   $form,
$form_state 
)

Provides validation of the instance settings form.

There is no equivalent function in the Drupal Field API. Validation of instance settings forms in Drupal is not supported. However, the TripalField provides this function to fill the gap. See the documentation for the instanceSettingsForm() function for instructions to support use of this function.

Parameters
$form
$form_state

Reimplemented in remote__data, so__transcript, and sbo__relationship.

◆ load()

TripalField::load (   $entity)

Loads the field values from the underlying data store.

Parameters
$entity
Returns
An array of the following format: $entity->{$field_name}['und'][0]['value'] = $value; where:
  • $entity is the entity object to which this field is attached.
  • $field_name is the name of this field
  • 'und' is the language code (in this case 'und' == undefined)
  • 0 is the cardinality. Increment by 1 when more than one item is available.
  • 'value' is the key indicating the value of this field. It should always be set. The value of the 'value' key will be the contents used for web services and for downloadable content. The value should be of the follow format types: 1) A single value (text, numeric, etc.) 2) An array of key value pair. 3) If multiple entries then cardinality should incremented and format types 1 and 2 should be used for each item. The array may contain as many other keys at the same level as 'value' but those keys are for internal field use and are not considered the value of the field.

Reimplemented in WebServicesField, remote__data, uo__unit, taxrank__infraspecific_taxon, so__transcript, so__genotype, so__cds, sio__vocabulary, sio__references, sio__annotation, sep__protocol, schema__publication, schema__alternate_name, schema__additional_type, sbo__relationship, sbo__phenotype, sbo__database_cross_reference, operation__phylotree_vis, operation__analysis, ogi__location_on_map, obi__organism, local__source_data, local__contact, go__gene_expression, efo__array_design, data__sequence_record, data__sequence_coordinates, data__sequence, data__protein_sequence, data__accession, chado_linker__prop, chado_linker__contact, rdfs__type, and content_type.

◆ query()

TripalField::query (   $query,
  $condition 
)

Used to filter records that match a given condition.

Records that belong to a content type can be filtered using the fields. This function should be implemented if the field supports filtering as specified in the elementInfo() function. With this function, the query object appropriate for the storage back-end is passed into the function.

The condition array passesd in will have three values:

  • column: the key indicating how the filter should occur.
  • op: the operation to perform (e.g. equals, contains, starts with etc.
  • value: the value for filtering.

The column used for filtering will be a comma-speperated list of controlled vocabulary IDs. This comma-separate list corresponds directly to the heirarchy of elements provided by the elementInfo() function. For example, if a field provides organism information then it may use the OBI:0100026 term for the field, and the term TAXRANK:0000005 for the term to indicate the 'Genus'. If these fields are properly organized in the elementInfo() function then the "column" of the condition when a user wants to search by genus will be: OBI:0100026,TAXRANK:0000005.

Parameters
$queryA query object appropriate for the data storage backend. For example, The Tripal Chado module will provide a SelectQuery object.
$conditionThe field specific condition as set in the TripalFieldQuery object.

Reimplemented in uo__unit, taxrank__infraspecific_taxon, sio__vocabulary, sio__annotation, sep__protocol, schema__alternate_name, schema__additional_type, sbo__relationship, sbo__database_cross_reference, operation__analysis, ogi__location_on_map, obi__organism, local__source_data, local__contact, efo__array_design, data__sequence_coordinates, data__accession, ChadoField, chado_linker__prop, and chado_linker__contact.

◆ queryOrder()

TripalField::queryOrder (   $query,
  $order 
)

Used to sort records that have been filtered.

Parameters
$queryA query object appropriate for the data storage backend. For example, The Tripal Chado module will provide a SelectQuery object.
$orderThe field ordering as set in the TripalFieldQuery object. This function should handle the ordering request as specified by this object.

Reimplemented in uo__unit, taxrank__infraspecific_taxon, sio__vocabulary, sio__annotation, sep__protocol, schema__alternate_name, schema__additional_type, sbo__relationship, sbo__database_cross_reference, operation__analysis, ogi__location_on_map, obi__organism, local__source_data, local__contact, efo__array_design, data__sequence_coordinates, data__accession, ChadoField, chado_linker__prop, and chado_linker__contact.

◆ settingsForm()

TripalField::settingsForm (   $has_data)

Provides a form for the 'Field Settings' of the field management page.

This is an optional hook function and is similar to the hook_field_settings_form function().

Parameters
$has_dataTRUE if the field already has data, FALSE if not.

Reimplemented in rdfs__type.

◆ settingsFormValidate()

TripalField::settingsFormValidate (   $form,
$form_state 
)

Validates the instance settings form.

Remember if you used the 'themeable' option for form elements you must copy the values correctly. See the description in hte instanceSettingsForm() function for details.

Parameters
$formThe form object.
$form_stateThe form_state object.

Reimplemented in schema__additional_type, and rdfs__type.

◆ settingsTheme()

TripalField::settingsTheme (   $element)

The theme function for the instance settings form.

Parameters
$elementA form element array containing basic properties for the widget:
  • #entity_type: The name of the entity the field is attached to.
  • #bundle: The name of the field bundle the field is contained in.
  • #field_name: The name of the field.
  • #language: The language the field is being edited in.
  • #field_parents: The 'parents' space for the field in the form. Most widgets can simply overlook this property. This identifies the location where the field values are placed within $form_state['values'], and is used to access processing information for the field through the field_form_get_state() and field_form_set_state() functions.
  • #columns: A list of field storage columns of the field.
  • #title: The sanitized element label for the field instance, ready for output.
  • #description: The sanitized element description for the field instance, ready for output.
  • #required: A Boolean indicating whether the element value is required; for required multiple value fields, only the first widget's values are required.
  • #delta: The order of this item in the array of subelements; see $delta above
Returns
A drupal renderable array or HTML or an empty string if no theming is to be applied.

Reimplemented in so__transcript.

◆ validate()

TripalField::validate (   $entity_type,
  $entity,
  $langcode,
  $items,
$errors 
)

Perform validation of the field regardless how it is updated.

Any errors encountered should be indicated by adding a value to the $errors array according to the instructions below.

Parameters
$entity_typeThe type of $entity.
$entityThe entity for the operation.
$langcodeThe language associated with $items.
$items$entity->{$field['field_name']}[$langcode], or an empty array if unset.
$errorsThe array of errors (keyed by field name, language code, and delta) that have already been reported for the entity. The function should add its errors to this array. Each error is an associative array with the following keys and values:
  • error: An error code (should be a string prefixed with the module name).
  • message: The human readable message to be displayed.

Reimplemented in sio__vocabulary, sio__annotation, sbo__relationship, sbo__database_cross_reference, operation__phylotree_vis, obi__organism, efo__array_design, and data__accession.

◆ viewsData()

TripalField::viewsData (   $view_base_id)

Describes this field to Views.

The child class need not implement this function has all of the details provided for elements by the elementInfo() function are used to generate the details needed for Views.

Parameters
$view_base_idViews was originally designed to integrate with SQL tables. And each field is associated with a table. Because these are TripalFields and views is not directly querying the tables it doesn't make sense to associate fields with a table, but we must associate the fields with the bundle. Each bundle is uniquely identified with the $view_base_id that is passed here.
Returns
An associative array describing the data structure. Primary key is the name used internally by Views for the bundle that is provided by the $view_base_id. The returned array should be compatible with the instructions provided by the hook_views_data() function.

◆ webServicesData()

TripalField::webServicesData ( )

Describes this field to Tripal web services.

The child class need not implement this function. It has all of the details provided for elements by the elementInfo() function are used to generate the details needed for Views.

Returns
An associative array with the keys available for searching. The value is the term array for the element.

Member Data Documentation

◆ $default_instance_settings

TripalField::$default_instance_settings
static
Initial value:
= [
'term_vocabulary' => 'schema',
'term_name' => 'Thing',
'term_accession' => 'Thing',
'term_fixed' => FALSE,
'auto_attach' => TRUE,
]

◆ $default_settings

TripalField::$default_settings
static
Initial value:
= [
'storage' => 'tripal_no_storage',
'searchable_keys' => [],
]

◆ $download_formatters

TripalField::$download_formatters
static
Initial value:
= [
'TripalTabDownloader',
'TripalCSVDownloader',
]

The documentation for this class was generated from the following file: