You are here

function link_process in Link 6

Same name and namespace in other branches
  1. 6.2 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 462
Defines simple link field types.

Code

function link_process($element, $edit, $form_state, $form) {
  $field = $form['#field_info'][$element['#field_name']];
  $delta = $element['#delta'];
  $element['url'] = array(
    '#type' => 'textfield',
    '#maxlength' => '255',
    '#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,
    );
  }
  if (!empty($field['attributes']['target']) && $field['attributes']['target'] == 'user') {
    $attributes = is_array($element['#value']['attributes']) ? $element['#value']['attributes'] : unserialize($element['#value']['attributes']);
    $element['attributes']['target'] = array(
      '#type' => 'checkbox',
      '#title' => t('Open URL in a New Window'),
      '#return_value' => "_blank",
      '#default_value' => isset($attributes['target']) ? $attributes['target'] : NULL,
    );
  }
  return $element;
}