You are here

function pmteam_form in Drupal PM (Project Management) 7

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

Implements hook_form().

File

pmteam/pmteam.module, line 145
Functionality for the Project Management Team module Organized into the following sections:

Code

function pmteam_form(&$node) {
  $breadcrumb = array(
    l(t('Project Management'), 'pm'),
    l(t('Teams'), 'pm/teams'),
  );
  drupal_set_breadcrumb($breadcrumb);
  $type = node_type_get_type($node);
  $info = field_info_extra_fields('node', 'pmteam', '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',
    '#weight' => $info['group1']['weight'],
  );
  $options = array(
    0 => '-',
  );
  $per_query = db_select('node', 'n');
  $per_query
    ->join('pmperson', 'spe', 'n.vid = spe.vid');
  $per_result = $per_query
    ->fields('n', array(
    'nid',
    'title',
  ))
    ->condition('n.type', 'pmperson')
    ->condition('n.status', 1)
    ->orderBy('n.title', 'ASC')
    ->addTag('node_access')
    ->execute();
  $people = array();
  foreach ($per_result as $person) {
    $people[$person->nid] = $person->title;
  }
  $options = $options + array(
    -1 => t('-PEOPLE-'),
  ) + $people;
  $org_result = db_select('node', 'n')
    ->fields('n', array(
    'nid',
    'title',
  ))
    ->condition('n.type', 'pmorganization')
    ->condition('n.status', 1)
    ->orderBy('n.title', 'ASC')
    ->addTag('node_access')
    ->execute();
  $organizations = array();
  foreach ($org_result as $organization) {
    $organizations[$organization->nid] = $organization->title;
  }
  $options = $options + array(
    -2 => t('-ORGANIZATIONS-'),
  ) + $organizations;
  $i = 1;
  $variable = 'members_array_' . $i;

  // Add rows for existing team members
  if (isset($node->members_array) && is_array($node->members_array)) {
    foreach ($node->members_array as $node->{$variable} => $name) {
      $form['group1'][$variable] = array(
        '#type' => 'select',
        '#title' => t('Team Member @num', array(
          '@num' => $i,
        )),
        '#options' => $options,
        '#default_value' => $node->{$variable},
      );
      $i++;
      $variable = 'members_array_' . $i;
    }
  }

  // Add placeholder rows
  for ($j = 0; $j < 3; $j++) {
    $variable = 'members_array_' . $i;
    $form['group1'][$variable] = array(
      '#type' => 'select',
      '#title' => t('Team Member @num', array(
        '@num' => $i,
      )),
      '#options' => $options,
      '#default_value' => isset($node->{$variable}) ? $node->{$variable} : NULL,
    );
    $i++;
  }
  $body = field_get_items('pmteam', $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;
}