You are here

function notifications_field_form_element in Notifications 6.4

Build a form element to edit a field

Parameters

$type: Field type

$value: Field value

$subscription: Subscription template or instance we are adding this field to

2 calls to notifications_field_form_element()
Notifications_Subscription::field_element in includes/notifications_subscription.class.inc
Display a form field for a notifications_field
notifications_subscription_list_form in ./notifications.pages.inc
List form for subscriptions of the same type for a user

File

includes/object.inc, line 378
Notifications object and fields

Code

function notifications_field_form_element($type, $value, $subscription = NULL, $title = FALSE, $required = FALSE, $size = 40) {
  $subscription_type = $subscription ? $subscription->type : NULL;
  $field_info = notifications_subscription_fields($type);
  $object_info = isset($field_info['object_type']) ? notifications_object_type($field_info['object_type']) : array();
  $merged_info = $field_info + $object_info;
  if (isset($merged_info['options callback'])) {
    $element['#type'] = 'select';
    $element['#options'] = notifications_field_subscription_options($type, $subscription);
  }
  elseif (!empty($merged_info['autocomplete path'])) {
    $element['#type'] = 'textfield';
    $element['#size'] = $size;
    $element['#autocomplete_path'] = $merged_info['autocomplete path'];
    if ($value) {
      if (!empty($merged_info['autocomplete callback'])) {
        $value = _notifications_field_callback($type, 'autocomplete callback', $value, $subscription);
      }
      elseif (!empty($merged_info['format callback'])) {
        $value = _notifications_field_callback($type, 'format callback', $value, FALSE);
      }
    }
  }
  else {
    $element['#type'] = 'textfield';
    if ($value) {
      $value = check_plain($value);
    }
  }
  if ($value) {
    $element['#default_value'] = $value;
  }
  if ($title) {
    $element['#title'] = notifications_field_format_name($type);
  }
  $element['#required'] = $required;
  return $element;
}