function matrix_cell_value in Matrix field 7.2
Same name and namespace in other branches
- 8.2 matrix.module \matrix_cell_value()
Find a value of a cell for either a string or a select list
Parameters
$item: array representing the cell
$field: array containing the field data
Return value
value to display
1 call to matrix_cell_value()
- matrix_field_formatter_view in ./
matrix.module - Implements hook_field_formatter_view().
File
- ./
matrix.module, line 860
Code
function matrix_cell_value($item, $field) {
$prefix = '';
$suffix = '';
if ($field['type'] == 'matrix_text') {
//selection lists cannot apply to text fields
$value = $item['value'];
}
elseif ($field['type'] == 'matrix_custom') {
//see if the cell contains a selection list
if (isset($field['settings']['settings'])) {
$settings = unserialize($field['settings']['settings']);
}
else {
$settings = array();
}
$define = $field['settings']['define'];
//work out which settings should be used
if ($define == 'rows') {
$field_settings = $settings['rows'][$item['row']];
}
else {
$field_settings = $settings['cols'][$item['col']];
}
//determine the value to return
$field_type = $field_settings['field_type'];
if (!in_array($field_type, array(
'select',
'radios',
'checkboxes',
))) {
$value = $item['value'];
$prefix = $field_settings[$field_type]['prefix'];
$suffix = $field_settings[$field_type]['suffix'];
}
else {
$allowed_values = matrix_allowed_values($field, $field_settings, $field_type);
$value = $allowed_values[$item['value']];
}
}
return check_plain($prefix . $value . $suffix);
}