function units_field_field_validate in Units of Measurement 7.2
Implements hook_field_validate().
File
- units_field/
units_field.module, line 176 - Provide field type for storing measured values.
Code
function units_field_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
foreach ($items as $delta => $item) {
try {
if ($item['expression']) {
$item['expression']
->getExpression()
->evaluate();
}
} catch (UnitsMathematicalExpressionDimensionException $e) {
$errors[$field['field_name']][$langcode][$delta][] = array(
'error' => 'units_mathematical_expression_dimension_inconsistency',
'message' => t('%name: the mathematical expression contains dimension inconsistency. Details: @exception', array(
'%name' => $instance['label'],
'@exception' => $e
->getMessage(),
)),
);
} catch (UnitsMathematicalExpressionMalformedException $e) {
$errors[$field['field_name']][$langcode][$delta][] = array(
'error' => 'units_mathematical_expression_malformed',
'message' => t('%name: the mathematical expression is malformed. Details: @exception', array(
'%name' => $instance['label'],
'@exception' => $e
->getMessage(),
)),
);
}
}
}