Tripal
|
Functions | |
hook_field_storage_tquery ($conditions, $orderBy) | |
hook_bundle_fields_info ($entity_type, $bundle) | |
hook_bundle_instances_info ($entity_type, $bundle) | |
tripal_field_is_empty ($field, $items, $delta=0) | |
tripal_get_field_types () | |
tripal_get_field_widgets () | |
tripal_get_field_formatters () | |
tripal_load_include_field_class ($class) | |
tripal_load_include_downloader_class ($class) | |
tripal_get_field_item_keyval ($items, $delta, $key, $default='') | |
tripal_format_views_field_element ($field_name, $term) | |
Provides an application programming interface (API) for working with fields attached to TripalEntity content types (bundles).
Fields: A field is a reusable "data container" that is attached to a Bundle. Programmatically, each field provides one or more primitive data types, with validators and widgets for editing and formatters for display. Each field independently manages the data to which it assigned. Just like with Bundles, Fields are also described using controlled vocabulary terms. For example, a gene Bundle has a field attached that provides the name of the gene. This field only provides the name and nothing more. Tripal uses the schema:name vocabulary term to describe the field.
Field Instances: Fields describe "atomic" units of data that are associated with an entity. For example, a "name" is an atomic unit of data about a Gene or Organism entity. Fields can be reused for multiple Bundles. For example, gene, mRNA, genetic markers and variants all have name data. Despite that all of these Bundles provides a "name", we only need one field to describe that this data is a "name". However, we may want to customize a field specific to each bundle. Therefore, an Instance of a field is attached to a bundle, and field instances can then be customized differently. The most important customization is the one that defines the Chado table from which the data for a field is retrieved. Despite that field instances are attached to bundles, they become visible with Entities. When an entity is loaded for display, Drupal examines all of the fields that are attached to the entity's bundle, and then populates the fields instances with data specific to the entity being loaded.
hook_bundle_fields_info | ( | $entity_type, | |
$bundle | |||
) |
Allows a module to return a bundles field info.
$entity_type | The name of the entity, like 'TripalEntity'. |
$bundle | The bundle object. |
hook_bundle_instances_info | ( | $entity_type, | |
$bundle | |||
) |
Allows a module to return the field instances of a bundle.
$entity_type | The name of the entity, most likely 'TripalEntity'. |
$bundle | The bundle object. |
hook_field_storage_tquery | ( | $conditions, | |
$orderBy | |||
) |
tripal_field_is_empty | ( | $field, | |
$items, | |||
$delta = 0 |
|||
) |
Indicate if a field has an empty value.
By default, all field values are attached to an entity in the form $entity->{field_name}[{language}][{delta}]. Typically a field will then have a 'value' element: $entity->{field_name}[{language}][{delta}]['value'] and if that value is empty then the field is considered empty by Tripal. By default the tripal_field_is_empty() function is used to check all fields to see if they are empty. However, this hook can be implemented by any module to override that behavior.
$field | A field array. |
$items | The array of items attached to entity. |
$delta | The specific value to check. For fields with cardinality greater than 1 then each value can be checked. Defaults to 0 indicating it will check the first value. |
tripal_format_views_field_element | ( | $field_name, | |
$term | |||
) |
Formats an element of a TripalField for use by Drupal Views.
Sometimes the value of TripalField can be more than just a single scalar. In this case the value is an array of key value pairs where each key is a controlled vocabulary term. In order to support fields, filtering and sorting by these sub elements using Drupal Views, the TripalField implementation must provide some help to Views by describing these elements, and then implementing a query() function to support them. However, the naming of sub elements must follow a set convention. This function guarantees proper naming for sub elements.
$field_name | The name of the field to which the element belongs. |
$term | The term object as returned by tripal_get_term_details(); |
tripal_get_field_formatters | ( | ) |
Retrieves a list of TripalFieldFormatters.
The TripalFieldFormatter classes can be added by a site developer and should be placed in the [module]/includes/TripalFields directory. Tripal will support any widget as long as it is in this directory and extends the TripalFieldFormatter class.
tripal_get_field_item_keyval | ( | $items, | |
$delta, | |||
$key, | |||
$default = '' |
|||
) |
More easily get the value of a single item from a field's items array.
A Drupal field attached to an entity may have multiple items (i.e. it has a cardinality > 1). Each of these items will always have a 'value' key that contains the data for that field. However, fields can also have other keys with their own values. You can easily retrieve the value of these keys using this function. What makes this function useful is that you can provide a default value to use if the key has no value. This is useful when developing a TripalField::widgetForm function and you need to retrieve default values and you don't want to have to always check if the value is set.
$items | The fields $items array. Compatible with that returned by field_get_items. |
$delta | The index of the item. @parm $key The name of the key within the item. |
$default | A default value to return if the key is not set. By default the empty string is returned. |
tripal_get_field_types | ( | ) |
Retrieves a list of TripalField types.
The TripalField classes can be added by a site developer and should be placed in the [module]/includes/TripalFields directory. Tripal will support any field as long as it is in this directory and extends the TripalField class. To support dynamic inclusion of new fields this function will look for TripalField class files and return a type for each one.
tripal_get_field_widgets | ( | ) |
Retrieves a list of TripalFieldWidgets.
The TripalFieldWidget classes can be added by a site developer and should be placed in the [module]/includes/TripalFields directory. Tripal will support any widget as long as it is in this directory and extends the TripalFieldWidget class.
tripal_load_include_downloader_class | ( | $class | ) |
Loads the TripalEntityDownloader file into scope.
$class | The name of the class to include. |
tripal_load_include_field_class | ( | $class | ) |
Loads the TripalField class file into scope.
$class | The class to include. This can be a TripalField, TripalFieldWidget or TripalFieldFormatter class name. |