View source
<?php
function elements_elements() {
$types['tableselect'] = array(
'#input' => TRUE,
'#js_select' => TRUE,
'#multiple' => TRUE,
'#process' => array(
'form_process_tableselect',
),
'#options' => array(),
'#empty' => '',
);
$types['emailfield'] = array(
'#input' => TRUE,
'#size' => 60,
'#maxlength' => 128,
'#autocomplete_path' => FALSE,
'#process' => array(
'form_expand_ahah',
),
'#value_callback' => 'form_type_textfield_value',
);
$types['searchfield'] = array(
'#input' => TRUE,
'#size' => 60,
'#maxlength' => 128,
'#autocomplete_path' => FALSE,
'#process' => array(
'form_expand_ahah',
),
'#value_callback' => 'form_type_textfield_value',
);
$types['telfield'] = array(
'#input' => TRUE,
'#size' => 20,
'#maxlength' => 64,
'#autocomplete_path' => FALSE,
'#process' => array(
'form_expand_ahah',
),
'#value_callback' => 'form_type_textfield_value',
);
$types['urlfield'] = array(
'#input' => TRUE,
'#size' => 80,
'#maxlength' => 128,
'#autocomplete_path' => FALSE,
'#process' => array(
'form_expand_ahah',
),
'#value_callback' => 'form_type_textfield_value',
);
$types['numberfield'] = array(
'#input' => TRUE,
'#process' => array(
'form_expand_ahah',
),
'#value_callback' => 'form_type_textfield_value',
);
$types['rangefield'] = array(
'#input' => TRUE,
'#process' => array(
'form_expand_ahah',
),
'#value_callback' => 'form_type_textfield_value',
);
$types['textfield'] = array(
'#process' => array(
'form_process_placeholder',
),
);
$types['textarea'] = array(
'#process' => array(
'form_process_placeholder',
),
);
$types['password'] = array(
'#process' => array(
'form_process_placeholder',
),
);
return $types;
}
function elements_theme() {
return array(
'tableselect' => array(
'arguments' => array(
'element' => NULL,
),
'file' => 'elements.theme.inc',
),
'emailfield' => array(
'arguments' => array(
'element' => NULL,
),
'file' => 'elements.theme.inc',
),
'searchfield' => array(
'arguments' => array(
'element' => NULL,
),
'file' => 'elements.theme.inc',
),
'telfield' => array(
'arguments' => array(
'element' => NULL,
),
'file' => 'elements.theme.inc',
),
'urlfield' => array(
'arguments' => array(
'element' => NULL,
),
'file' => 'elements.theme.inc',
),
'numberfield' => array(
'arguments' => array(
'element' => NULL,
),
'file' => 'elements.theme.inc',
),
'rangefield' => array(
'arguments' => array(
'element' => NULL,
),
'file' => 'elements.theme.inc',
),
);
}
function elements_add_autocomplete(&$element) {
$output = '';
if (!empty($element['#autocomplete_path']) && menu_valid_path(array(
'link_path' => $element['#autocomplete_path'],
))) {
drupal_add_js('misc/autocomplete.js');
$element['#attributes']['class'] .= ' form-autocomplete';
$attributes = array();
$attributes['type'] = 'hidden';
$attributes['id'] = $element['#attributes']['id'] . '-autocomplete';
$attributes['value'] = url($element['#autocomplete_path'], array(
'absolute' => TRUE,
));
$attributes['disabled'] = 'disabled';
$attributes['class'] = 'autocomplete';
$output = '<input' . drupal_attributes($attributes) . ' />';
}
return $output;
}
function form_process_placeholder($element) {
if (isset($element['#placeholder']) && !isset($element['#attributes']['placeholder'])) {
$element['#attributes']['placeholder'] = $element['#placeholder'];
}
return $element;
}
function element_set_attributes(array &$element, array $map) {
foreach ($map as $property => $attribute) {
if (is_int($property)) {
$property = '#' . $attribute;
}
if (isset($element[$property]) && !isset($element['#attributes'][$attribute])) {
$element['#attributes'][$attribute] = $element[$property];
}
}
}
function form_process_tableselect($element) {
if ($element['#multiple']) {
$value = is_array($element['#value']) ? $element['#value'] : array();
}
else {
$element['#js_select'] = FALSE;
}
$element['#tree'] = TRUE;
if (count($element['#options']) > 0) {
if (!isset($element['#default_value']) || $element['#default_value'] === 0) {
$element['#default_value'] = array();
}
foreach ($element['#options'] as $key => $choice) {
if (!isset($element[$key])) {
if ($element['#multiple']) {
$element[$key] = array(
'#type' => 'checkbox',
'#title' => '',
'#return_value' => $key,
'#default_value' => isset($value[$key]),
'#attributes' => $element['#attributes'],
'#ahah' => isset($element['#ahah']) ? $element['#ahah'] : NULL,
);
}
else {
$parents_for_id = array_merge($element['#parents'], array(
$key,
));
$element[$key] = array(
'#type' => 'radio',
'#title' => '',
'#return_value' => $key,
'#default_value' => $element['#default_value'] == $key ? $key : NULL,
'#attributes' => $element['#attributes'],
'#parents' => $element['#parents'],
'#id' => form_clean_id('edit-' . implode('-', $parents_for_id)),
'#ahah' => isset($element['#ahah']) ? $element['#ahah'] : NULL,
);
}
if (isset($element['#options'][$key]['#weight'])) {
$element[$key]['#weight'] = $element['#options'][$key]['#weight'];
}
}
}
}
else {
$element['#value'] = array();
}
return $element;
}