function link_process in Link 6.2
Same name and namespace in other branches
- 6 link.module \link_process()
Process the link type element before displaying the field.
Build the form element. When creating a form using FAPI #process, note that $element['#value'] is already set.
The $fields array is in $form['#field_info'][$element['#field_name']].
1 string reference to 'link_process'
- link_elements in ./
link.module - Implementation of hook_elements().
File
- ./
link.module, line 345 - Defines simple link field types.
Code
function link_process($element, $edit, $form_state, $form) {
module_load_include('inc', 'link');
$field = $form['#field_info'][$element['#field_name']];
$delta = $element['#delta'];
$element['url'] = array(
'#type' => 'textfield',
'#maxlength' => LINK_URL_MAX_LENGTH,
'#title' => t('URL'),
'#description' => $element['#description'],
'#required' => $delta == 0 && $field['url'] !== 'optional' ? $element['#required'] : FALSE,
'#default_value' => isset($element['#value']['url']) ? $element['#value']['url'] : NULL,
);
if ($field['title'] != 'none' && $field['title'] != 'value') {
$element['title'] = array(
'#type' => 'textfield',
'#maxlength' => '255',
'#title' => t('Title'),
'#required' => $delta == 0 && $field['title'] == 'required' ? $field['required'] : FALSE,
'#default_value' => isset($element['#value']['title']) ? $element['#value']['title'] : NULL,
);
}
// Initialize field attributes as an array if it is not an array yet.
if (!is_array($field['attributes'])) {
$field['attributes'] = array();
}
// Add default atrributes.
$field['attributes'] += _link_default_attributes();
$attributes = isset($element['#value']['attributes']) ? $element['#value']['attributes'] : $field['attributes'];
if (!empty($field['attributes']['target']) && $field['attributes']['target'] == LINK_TARGET_USER) {
$element['attributes']['target'] = array(
'#type' => 'checkbox',
'#title' => t('Open URL in a New Window'),
'#return_value' => LINK_TARGET_NEW_WINDOW,
'#default_value' => $attributes['target'],
);
}
return $element;
}