im building module that add a new widget to fields already exi开发者_JAVA技巧st in drupal . drupal using this hook to validate this field
function list_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
$allowed_values = list_allowed_values($field);
foreach ($items as $delta => $item) {
if (!empty($item['value'])) { // =======> the problem is here
if (!empty($allowed_values) && !isset($allowed_values[$item['value']])) {
$errors[$field['field_name']][$langcode][$delta][] = array(
'error' => 'list_illegal_value',
'message' => t('%name: illegal value.', array('%name' => $instance['label'])),
);
}
}
}
}
THE PROBLEM IS : when i add new field with my new widget...and i save the field settings i got the message:
list_illegal_value then i found that $item have no key ['value']...
foreach ($items as $delta => $item) {
my result is in $item it self no $item['value'] so how i can add this key ['value'] to variable $item with out modifying the core validation hook
ok this problem is solved for me ... if you created a new widget for exist field and found this error
list_illegal_value
make sure that you have created your widget form as the following
$element['value'] += array( // dont forget ['value'] it will couse this problem
'#title' => t( '@title' , array('@title' => $label)) ,
'#type' => 'select' ,
...etc
精彩评论