You are here

function pmproject_form in Drupal PM (Project Management) 7

Same name and namespace in other branches
  1. 8 pmproject/pmproject.module \pmproject_form()
  2. 7.3 pmproject/pmproject.module \pmproject_form()
  3. 7.2 pmproject/pmproject.module \pmproject_form()

Implements hook_form().

File

pmproject/pmproject.module, line 227

Code

function pmproject_form(&$node) {
  $breadcrumb = array();
  $breadcrumb[] = l(t('Project Management'), 'pm');
  $breadcrumb[] = l(t('Projects'), 'pm/projects');
  drupal_set_breadcrumb($breadcrumb);
  $org_query = db_select('node', 'n');
  $org_query
    ->join('pmorganization', 'sor', 'n.vid = sor.vid');
  $org_query
    ->fields('n', array(
    'nid',
    'title',
  ))
    ->condition('n.status', 1)
    ->condition('n.type', 'pmorganization')
    ->addTag('node_access')
    ->orderBy('n.title', 'ASC');
  $type = node_type_get_type($node);
  $info = field_info_extra_fields('node', 'pmproject', 'form');
  $form['#attributes']['class'] = 'pmcomponent_node_form';
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => check_plain($type->title_label),
    '#required' => TRUE,
    '#default_value' => $node->title,
    '#weight' => $info['title']['weight'],
  );
  $form['group1'] = array(
    '#type' => 'markup',
    '#theme' => 'pm_form_group',
    '#weight' => $info['group1']['weight'],
  );
  $org_result = $org_query
    ->execute();
  $organizations = array();
  foreach ($org_result as $organization) {
    $organizations[$organization->nid] = $organization->title;
    if (!isset($node->organization_nid)) {
      $node->organization_nid = $organization->nid;
    }
  }
  if (!isset($node->organization_nid)) {
    drupal_set_message(t('Please add an orgnization to the system before trying to add a project.'), 'error');
  }
  $form['group1']['organization_nid'] = array(
    '#type' => 'select',
    '#title' => t('Organization'),
    '#options' => $organizations,
    '#default_value' => isset($node->organization_nid) ? $node->organization_nid : NULL,
  );
  $form['group1']['organization_nid_old'] = array(
    '#type' => 'hidden',
    '#default_value' => isset($node->organization_nid) ? $node->organization_nid : NULL,
  );
  $form['group2'] = array(
    '#type' => 'markup',
    '#theme' => 'pm_form_group',
    '#weight' => $info['group2']['weight'],
  );
  $category_list = pm_attributes_bydomain('Project category');
  $form['group2']['projectcategory'] = array(
    '#type' => 'select',
    '#title' => t('Category'),
    '#default_value' => isset($node->projectcategory) ? $node->projectcategory : $category_list['default'],
    '#options' => $category_list['values'],
  );
  $status_list = pm_attributes_bydomain('Project status');
  $form['group2']['projectstatus'] = array(
    '#type' => 'select',
    '#title' => t('Status'),
    '#default_value' => isset($node->projectstatus) ? $node->projectstatus : $status_list['default'],
    '#options' => $status_list['values'],
  );
  $priority_list = pm_attributes_bydomain('Project priority');
  $form['group2']['projectpriority'] = array(
    '#type' => 'select',
    '#title' => t('Priority'),
    '#default_value' => isset($node->projectpriority) ? $node->projectpriority : $priority_list['default'],
    '#options' => $priority_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'],
  );
  $people = $options = pm_get_assignment_options(isset($node->organization_nid) ? $node->organization_nid : 0, isset($node->nid) ? $node->nid : 0);
  if (isset($people['Teams:'])) {
    unset($people['Teams:']);
  }
  $form['group5']['manager_nid'] = array(
    '#type' => module_exists('pmperson') ? 'select' : 'hidden',
    '#title' => t('Project manager'),
    '#options' => $people,
    '#default_value' => isset($node->manager_nid) ? $node->manager_nid : 0,
  );
  $form['group5']['assigned_nid'] = array(
    '#type' => module_exists('pmperson') ? 'select' : 'hidden',
    '#title' => t('Assigned to'),
    '#options' => $options,
    '#default_value' => isset($node->assigned_nid) ? $node->assigned_nid : 0,
  );

  // Check to see if the body field is still there, if so, display it.
  $body = field_get_items('pmproject', $node, 'body');
  if ($body) {
    $form['body_field'] = $body;
  }
  $form['title_old'] = array(
    '#type' => 'hidden',
    '#default_value' => isset($node->title_old) ? $node->title_old : NULL,
  );
  return $form;
}