function _link_validate in Link 6
Same name and namespace in other branches
- 6.2 link.inc \_link_validate()
- 7 link.module \_link_validate()
1 call to _link_validate()
- link_field in ./
link.module - Implementation of hook_field().
File
- ./
link.module, line 264 - Defines simple link field types.
Code
function _link_validate(&$item, $delta, $field, $node, &$optional_field_found) {
if ($item['url'] && !(isset($field['widget']['default_value'][$delta]['url']) && $item['url'] == $field['widget']['default_value'][$delta]['url'] && !$field['required'])) {
// Validate the link.
if (link_validate_url(trim($item['url'])) == FALSE) {
form_set_error($field['field_name'] . '][' . $delta . '][url', t('Not a valid URL.'));
}
// Require a title for the link if necessary.
if ($field['title'] == 'required' && strlen(trim($item['title'])) == 0) {
form_set_error($field['field_name'] . '][' . $delta . '][title', t('Titles are required for all links.'));
}
}
// Require a link if we have a title.
if ($field['url'] !== 'optional' && strlen($item['title']) > 0 && strlen(trim($item['url'])) == 0) {
form_set_error($field['field_name'] . '][' . $delta . '][url', t('You cannot enter a title without a link url.'));
}
// In a totally bizzaro case, where URLs and titles are optional but the field is required, ensure there is at least one link.
if ($field['url'] == 'optional' && $field['title'] == 'optional' && (strlen(trim($item['url'])) != 0 || strlen(trim($item['title'])) != 0)) {
$optional_field_found = TRUE;
}
}