function _editablefields_drupal_get_form in Editable Fields 5.3
Same name and namespace in other branches
- 5 editablefields.module \_editablefields_drupal_get_form()
- 5.2 editablefields.module \_editablefields_drupal_get_form()
2 calls to _editablefields_drupal_get_form()
File
- ./
editablefields.module, line 512
Code
function _editablefields_drupal_get_form($process = false, $type, $view) {
global $viewfield_stack;
$tmp = $viewfield_stack;
$viewfield_stack = array();
global $user;
$form_id = $type . '_node_form';
$node = array(
'uid' => $user->uid,
'name' => $user->name,
'type' => $type,
'language' => '',
);
$form_state = array(
'storage' => NULL,
'submitted' => FALSE,
);
$form_state['post'] = $_POST;
$form = drupal_retrieve_form($form_id, $node);
drupal_prepare_form($form_id, $form, $form_state);
$form_build_id = 'form-' . md5(mt_rand());
$form['#build_id'] = $form_build_id;
$form['editablefields_addnew_form'] = array(
'#type' => 'hidden',
'#value' => $type,
);
foreach ($view->argument as $id => $arg) {
if (preg_match('/^content: (field_.*)$/', $arg['type'], $matches)) {
$fieldname = $matches[1];
if (is_array($view->args[$id])) {
$form['editablefieldsfiltervalue_' . $fieldname] = array(
'#type' => 'value',
'#value' => $view->args[$id],
);
}
else {
$form['editablefieldsfiltervalue_' . $fieldname] = array(
'#type' => 'value',
'#value' => array(
$view->args[$id],
),
);
}
}
}
foreach ($view->filter as $filter) {
if (preg_match('/^node_data_(.*)\\.\\1_(.*)$/', $filter['field'], $matches)) {
$fieldname = $matches[1];
$valuename = $matches[2];
$form['editablefieldsfiltervalue_' . $fieldname] = array(
'#type' => 'value',
'#value' => $filter['value'],
);
}
}
unset($form['preview']);
// preview really gets in the way of this functionality
drupal_prepare_form($form_id, $form, $form_state);
$colspan = 0;
foreach ($view->field as $vf => $vfield) {
$colspan++;
foreach ($form as $fn => $fi) {
if ($vfield['field'] == $fn . "_value") {
if ($form[$fn][0]['value']['#type'] != 'value') {
$form[$fn]['#prefix'] = '<td colspan=' . $colspan . '>';
$form[$fn]['#suffix'] = '</td>';
$colspan = 0;
}
}
}
}
$newform = array();
// $newform['form_editablefield_row']=array('#type' => 'fieldset', '#prefix' => '<tr class=form_edit_line>', '#suffix' => '</tr>', '#weight' =>0);
// $newform['form_editablefield_other']=array('#type' => 'fieldset', '#prefix' => '<tr class=form_edit_line><td colspan=0>', '#suffix' => '</td></tr>','#weight' =>10);
$newform['form_editablefield_row'] = array(
'#type' => 'fieldset',
'#prefix' => '<tr class=form_edit_line>',
'#suffix' => '</tr>',
);
$newform['form_editablefield_other'] = array(
'#type' => 'fieldset',
'#collapsible' => 'TRUE',
'#collapsed' => 'TRUE',
'#prefix' => '<tr class=form_edit_line><td colspan=0>',
'#suffix' => '</td></tr>',
);
foreach ($form as $fn => $fi) {
if (is_array($form[$fn]) && strncmp($fn, '#', 1) != 0) {
$inview = 0;
foreach ($view->field as $vf => $vfield) {
if (strncmp($fn . "_", $vfield['field'], strlen($fn) + 1) == 0) {
$inview++;
}
}
if ($inview) {
$newform['form_editablefield_row'][$fn] = $form[$fn];
}
else {
$newform['form_editablefield_other'][$fn] = $form[$fn];
}
// unset($form[$fn]);
}
else {
$newform[$fn] = $fi;
}
}
$form = $newform;
// print_r($form);
//if (!empty($form['#cache'])) {
// By not sending the form state, we avoid storing the storage which
// won't have been touched yet.
// form_set_cache($form_build_id, $form, NULL);
//}
unset($form_state['post']);
$form['#post'] = $_POST;
if ($process) {
drupal_process_form($form_id, $form, $form_state);
}
$viewfield_stack = $tmp;
return $form;
}