function tripal_get_field_item_keyval

3.x tripal.fields.api.inc 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 retreive 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 retreive default values and you don't want to have to always check if the value is set.

@parm $key The name of the key within the item.

Parameters

$items: The fields $items array. Compatbile with that returned by field_get_items.

$delta: The index of the item.

$default: A default value to return if the key is not set. By default the empty string is returned.

Return value

The value assigned to the item's key; FALSE if the key doesn't exist or the $default argument if no value is associated with the key.

Related topics

7 calls to tripal_get_field_item_keyval()
chado_linker__contact_widget::form in tripal_chado/includes/TripalFields/chado_linker__contact/chado_linker__contact_widget.inc
chado_linker__prop_widget::form in tripal_chado/includes/TripalFields/chado_linker__prop/chado_linker__prop_widget.inc
local__contact_widget::form in tripal_chado/includes/TripalFields/local__contact/local__contact_widget.inc
sbo__database_cross_reference_widget::form in tripal_chado/includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference_widget.inc
sbo__relationship_widget::form in tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship_widget.inc

... See full list

File

tripal/api/tripal.fields.api.inc, line 441
Provides an application programming interface (API) for working with fields attached to TripalEntity content types (bundles).

Code

function tripal_get_field_item_keyval($items, $delta, $key, $default = '') {
  if (!array_key_exists($delta, $items)) {
    return FALSE;
  }
  if (!array_key_exists($key, $items[$delta])) {
    return FALSE;
  }
  if (!$items[$delta][$key]) {
    return $default;
  }
  return $items[$delta][$key];
}