function itoggle_field_field_widget_form in iToggle 7.2
Implements hook_field_widget_form().
File
- modules/
field/ itoggle_field.module, line 137 - iToggle Field module.
Code
function itoggle_field_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
$instance_default = isset($instance['default_value'][$delta]['value']) ? $instance['default_value'][$delta]['value'] : 0;
if (isset($form['vid']['#value'])) {
$default_value = isset($items[$delta]['value']) && $items[$delta]['value'] == 1 ? 1 : 0;
}
else {
$default_value = isset($items[$delta]['value']) ? $items[$delta]['value'] : $instance_default;
}
$element += array(
'#type' => 'checkbox',
'#default_value' => $default_value,
'#on_value' => 1,
'#off_value' => 0,
'#title' => $instance['label'],
'#element_validate' => array(
'itoggle_field_field_widget_validate',
),
'#after_build' => array(
'itoggle_hide_checkbox',
),
'#value_key' => 'value',
);
$required = $instance['required'] == 1 ? ' <span title="' . t('This field is required.') . '" class="form-required">*</span>' : '';
$label = $instance['label'];
$property_prefix = empty($element['#field_parents']) ? '' : implode('-', $element['#field_parents']) . '-';
$form["itoggle_helper_{$field['field_name']}"] = array(
'#theme' => 'itoggle',
'#type' => $instance['entity_type'],
'#bundle' => $instance['bundle'],
'#id' => $field['field_name'],
'#property' => $property_prefix . $field['field_name'],
'#checked' => $default_value,
'#scope' => 'field-edit',
'#display_type' => $instance['widget']['settings']['display_type'],
'#prefix' => "<div class=\"form-item form-type-itoggle form-item-{$field['field_name']}\"><label class=\"field-label\">{$label}{$required}</label>",
'#suffix' => '<div class="clearfix"></div></div>',
'#weight' => $instance['widget']['weight'],
);
// Play nice with Field Group module.
if (module_exists('field_group')) {
if (!isset($form['#after_build']) || !in_array('itoggle_form_field_group_after_build', $form['#after_build'])) {
$form['#after_build'][] = 'itoggle_form_field_group_after_build';
}
}
return $element;
}