function ref_field_field_validate in (Entity)Reference Field Synchronization 7
Implements hook_field_validate().
Possible error codes:
- 'ref_field_invalid_rel': The given id is not from a valid 'entity'.
- 'ref_field_auto_reference': Self reference detected.
File
- ./
ref_field.module, line 233
Code
function ref_field_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
$entity_info = entity_get_info($entity_type);
foreach ($items as $delta => $item) {
if ($item['eid'] && !entity_load($field['settings']['entity'], array(
$item['eid'],
))) {
$errors[$field['field_name']][$langcode][$delta][] = array(
'error' => 'ref_field_invalid_rel',
'message' => t('%name: you selected an invalid %entity.', array(
'%name' => $instance['label'],
'%entity' => $field['settings']['entity'],
)),
);
}
if ($field['settings']['entity'] == $entity_type && $item['eid'] && $item['eid'] == $entity->{$entity_info}['entity keys']['id']) {
$errors[$field['field_name']][$langcode][$delta][] = array(
'error' => 'ref_field_auto_reference',
'message' => t('%name: self-reference are not allowed, please change the value.', array(
'%name' => $instance['label'],
)),
);
}
}
}