function pmtask_form in Drupal PM (Project Management) 7
Same name and namespace in other branches
- 8 pmtask/pmtask.module \pmtask_form()
- 7.3 pmtask/pmtask.module \pmtask_form()
- 7.2 pmtask/pmtask.module \pmtask_form()
Implements hook_form().
File
- pmtask/
pmtask.module, line 207
Code
function pmtask_form($node, &$form_state) {
$breadcrumb = array(
l(t('Project Management'), 'pm'),
l(t('Tasks'), 'pm/tasks'),
);
drupal_set_breadcrumb($breadcrumb);
$type = node_type_get_type($node);
$info = field_info_extra_fields('node', 'pmtask', 'form');
$form['#prefix'] = '<div id="pmtask-form-wrapper">';
$form['#suffix'] = '</div>';
$form['group1'] = array(
'#type' => 'markup',
'#theme' => 'pm_form_group',
'#weight' => $info['group1']['weight'],
);
$org_query = db_select('node', 'n');
$org_query
->join('pmorganization', 'sor', 'n.vid = sor.vid');
$org_result = $org_query
->fields('n', array(
'nid',
'title',
))
->condition('n.status', 1)
->condition('sor.isactive', 1)
->condition('n.type', 'pmorganization')
->addTag('node_access')
->orderBy('n.title', 'ASC')
->execute();
$organizations = array();
foreach ($org_result as $organization) {
$organizations[$organization->nid] = $organization->title;
if (!isset($node->organization_nid)) {
$node->organization_nid = $organization->nid;
}
}
$form['group1']['organization_nid'] = array(
'#type' => 'select',
'#title' => t('Organization'),
'#default_value' => isset($node->organization_nid) ? $node->organization_nid : NULL,
'#options' => $organizations,
'#required' => TRUE,
'#ajax' => array(
'callback' => 'pmtask_form_ajax',
'wrapper' => 'pmtask-form-wrapper',
),
);
if (isset($node->organization_nid)) {
$organization_nid = isset($form_state['values']['organization_nid']) ? $form_state['values']['organization_nid'] : $node->organization_nid;
}
else {
drupal_set_message(t('Please add an organization to the system before trying to add a task.'), 'error');
$organization_nid = NULL;
}
$pro_query = db_select('node', 'n');
$pro_query
->join('pmproject', 'spr', 'n.vid = spr.vid');
$pro_result = $pro_query
->fields('n', array(
'nid',
'title',
))
->condition('n.status', 1)
->condition('spr.organization_nid', $organization_nid)
->condition('n.type', 'pmproject')
->addTag('node_access')
->orderBy('n.title', 'ASC')
->execute();
$projects = array();
foreach ($pro_result as $project) {
$projects[$project->nid] = $project->title;
if (!isset($node->project_nid)) {
$node->project_nid = $project->nid;
}
}
$form['group1']['project_nid'] = array(
'#type' => 'select',
'#title' => t('Project'),
'#default_value' => isset($node->project_nid) ? $node->project_nid : NULL,
'#options' => $projects,
'#required' => TRUE,
'#prefix' => '<div id="pmtask-project-nid">',
'#suffix' => '</div>',
'#ajax' => array(
'callback' => 'pmtask_form_ajax',
'wrapper' => 'pmtask-form-wrapper',
),
);
$form['group1']['project_nid_old'] = array(
'#type' => 'hidden',
'#default_value' => isset($node->project_nid) ? $node->project_nid : NULL,
);
if (isset($node->project_nid)) {
$project_nid = isset($form_state['values']['project_nid']) ? $form_state['values']['project_nid'] : $node->project_nid;
}
else {
drupal_set_message(t('Please add a project to the system before trying to add a task.'), 'error');
$project_nid = NULL;
}
$tree = is_null($project_nid) ? array() : _pmtask_get_tree($project_nid);
$parent_tasks = _pmtask_plain_tree($tree);
$form['group1']['parent_nid'] = array(
'#type' => 'select',
'#title' => t('Parent task'),
'#default_value' => isset($node->parent_nid) ? $node->parent_nid : 0,
'#options' => array(
0 => '-',
) + $parent_tasks,
);
$form['group1']['weight'] = array(
'#type' => 'weight',
'#title' => t('Weight'),
'#default_value' => isset($node->weight) ? $node->weight : 0,
);
$form['group1']['stepno'] = array(
'#type' => 'textfield',
'#title' => t('Step no.'),
'#size' => 15,
'#required' => FALSE,
'#default_value' => isset($node->stepno) ? $node->stepno : NULL,
);
$form['title'] = array(
'#type' => 'textfield',
'#title' => check_plain($type->title_label),
'#required' => TRUE,
'#default_value' => $node->title,
'#weight' => $info['title']['weight'],
);
$form['group2'] = array(
'#type' => 'markup',
'#theme' => 'pm_form_group',
'#weight' => $info['group2']['weight'],
);
$taskcategory_list = pm_attributes_bydomain('Task category');
$form['group2']['taskcategory'] = array(
'#type' => 'select',
'#title' => t('Category'),
'#default_value' => isset($node->taskcategory) ? $node->taskcategory : $taskcategory_list['default'],
'#options' => $taskcategory_list['values'],
);
$taskstatus_list = pm_attributes_bydomain('Task status');
$form['group2']['taskstatus'] = array(
'#type' => 'select',
'#title' => t('Status'),
'#default_value' => isset($node->taskstatus) ? $node->taskstatus : $taskstatus_list['default'],
'#options' => $taskstatus_list['values'],
);
$taskpriority_list = pm_attributes_bydomain('Task priority');
$form['group2']['taskpriority'] = array(
'#type' => 'select',
'#title' => t('Priority'),
'#default_value' => isset($node->taskpriority) ? $node->taskpriority : $taskpriority_list['default'],
'#options' => $taskpriority_list['values'],
);
$form['group3'] = array(
'#type' => 'markup',
'#theme' => 'pm_form_group',
'#weight' => $info['group3']['weight'],
);
$durationunit_list = pm_attributes_bydomain('Duration unit');
$form['group3']['durationunit'] = array(
'#type' => 'select',
'#title' => t('Duration unit'),
'#default_value' => isset($node->durationunit) ? $node->durationunit : $durationunit_list['default'],
'#options' => $durationunit_list['values'],
);
$form['group3']['duration'] = array(
'#type' => 'textfield',
'#title' => t('Duration'),
'#size' => 20,
'#default_value' => isset($node->duration) ? $node->duration : NULL,
);
$form['group4'] = array(
'#type' => 'markup',
'#theme' => 'pm_form_group',
'#weight' => $info['group4']['weight'],
);
$pricemode_list = pm_attributes_bydomain('Price mode');
$form['group4']['pricemode'] = array(
'#type' => 'select',
'#title' => t('Price mode'),
'#default_value' => isset($node->pricemode) ? $node->pricemode : $pricemode_list['default'],
'#options' => $pricemode_list['values'],
);
$form['group4']['price'] = array(
'#title' => t('Price'),
'#type' => 'textfield',
'#size' => 15,
'#default_value' => isset($node->price) ? $node->price : NULL,
);
$currency_list = pm_attributes_bydomain('Currency');
$form['group4']['currency'] = array(
'#type' => 'select',
'#title' => t('Price currency'),
'#default_value' => isset($node->currency) ? $node->currency : $currency_list['default'],
'#options' => $currency_list['values'],
);
$form['group5'] = array(
'#type' => 'markup',
'#theme' => 'pm_form_group',
'#weight' => $info['group5']['weight'],
);
$options = pm_get_assignment_options($organization_nid, $project_nid);
$assigned_nid = isset($form_state['values']['assigned_nid']) ? $form_state['values']['assigned_nid'] : (isset($node->assigned_nid) ? $node->assigned_nid : 0);
$form['group5']['assigned_nid'] = array(
'#type' => 'select',
'#title' => t('Assigned to'),
'#options' => $options,
'#default_value' => $assigned_nid,
);
$form['group6'] = array(
'#type' => 'markup',
'#theme' => 'pm_form_group',
'#weight' => $info['group6']['weight'],
);
// Check to see if the body field is still there, if so, display it.
$body = field_get_items('pmtask', $node, 'body');
if ($body) {
$form['body_field'] = $body;
}
$form['stepno_old'] = array(
'#type' => 'hidden',
'#default_value' => isset($node->stepno_old) ? $node->stepno_old : NULL,
);
$form['title_old'] = array(
'#type' => 'hidden',
'#default_value' => isset($node->title_old) ? $node->title_old : NULL,
);
return $form;
}