You are here

function pmperson_form in Drupal PM (Project Management) 7

Implements hook_form().

File

pmperson/pmperson.module, line 222

Code

function pmperson_form(&$node) {
  $breadcrumb = array();
  $breadcrumb[] = l(t('Project Management'), 'pm');
  $breadcrumb[] = l(t('People'), 'pm/people');
  drupal_set_breadcrumb($breadcrumb);
  $type = node_type_get_type($node);
  $info = field_info_extra_fields('node', 'pmperson', 'form');
  $form['#attributes']['class'] = 'pmcomponent_node_form';
  $form['group1'] = array(
    '#type' => 'markup',
    '#theme' => 'pm_form_group',
    '#weight' => $info['group1']['weight'],
  );
  $form['group1']['prefix'] = array(
    '#type' => 'textfield',
    '#title' => t('Prefix'),
    '#size' => 20,
    '#default_value' => isset($node->prefix) ? $node->prefix : '',
  );
  $form['group1']['title'] = array(
    '#type' => 'textfield',
    '#title' => check_plain($type->title_label),
    '#required' => TRUE,
    '#default_value' => $node->title,
    '#size' => 40,
  );
  $form['group2'] = array(
    '#type' => 'markup',
    '#theme' => 'pm_form_group',
    '#weight' => $info['group2']['weight'],
  );
  $query = db_select('node', 'n');
  $query
    ->join('pmorganization', 'sor', 'sor.vid = n.vid');
  $result = $query
    ->fields('n', array(
    'nid',
    'title',
  ))
    ->condition('n.status', 1)
    ->condition('n.type', 'pmorganization')
    ->orderBy('n.title', 'ASC')
    ->addTag('node_access')
    ->execute();
  $organizations = array();
  foreach ($result as $organization) {
    $organizations[$organization->nid] = $organization->title;
    if (!isset($node->organization_nid)) {
      $node->organization_nid = $organization->nid;
    }
  }
  if (empty($organizations)) {
    $message = t('Before you add a Person, you must first !link.', array(
      '!link' => l(t('add an Organization'), 'node/add/pmorganization'),
    ));

    // No user entered text in $message, so ignore coder warning.
    // @ignore security_dsm
    drupal_set_message($message, 'error');
  }
  $form['group2']['organization_nid'] = array(
    '#type' => 'select',
    '#title' => t('Organization'),
    '#default_value' => isset($node->organization_nid) ? $node->organization_nid : NULL,
    '#options' => $organizations,
    '#required' => TRUE,
    '#attributes' => array(
      'onchange' => "pmperson_organization_project_tasks(this, 'edit-project-nid', 'edit-parent-nid', true, '-')",
    ),
  );
  $form['group2']['user_name'] = array(
    '#type' => 'textfield',
    '#title' => t('User'),
    '#default_value' => isset($node->user_name) ? $node->user_name : '',
    '#autocomplete_path' => 'pm/pmperson_js',
    '#size' => 40,
  );
  $form['group3'] = array(
    '#type' => 'markup',
    '#theme' => 'pm_form_group',
    '#weight' => $info['group3']['weight'],
  );
  $form['group3']['email'] = array(
    '#type' => 'textfield',
    '#title' => t('E-mail'),
    '#size' => 30,
    // Ignore use of $node->email rather than $node->mail.
    // @ignore coder_tough_love_8
    '#default_value' => isset($node->email) ? $node->email : '',
  );
  $form['group3']['www'] = array(
    '#type' => 'textfield',
    '#title' => t('WWW'),
    '#size' => 30,
    '#default_value' => isset($node->www) ? $node->www : '',
  );
  $form['group4'] = array(
    '#type' => 'markup',
    '#theme' => 'pm_form_group',
    '#weight' => $info['group4']['weight'],
  );
  $form['group4']['phone'] = array(
    '#type' => 'textfield',
    '#title' => t('Phone'),
    '#size' => 30,
    '#default_value' => isset($node->phone) ? $node->phone : '',
  );
  $form['group4']['im'] = array(
    '#type' => 'textfield',
    '#title' => t('IM'),
    '#size' => 30,
    '#default_value' => isset($node->im) ? $node->im : '',
  );

  // Check to see if the body field is still there, if so, display it.
  $body = field_get_items('pmperson', $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;
}