You are here

function pm_attribute_form in Drupal PM (Project Management) 7

Defines attribute list form.

2 calls to pm_attribute_form()
pm_attribute_add in ./pm.admin.inc
Callback for attribute add page.
pm_attribute_edit in ./pm.admin.inc
Define attribute edit form.

File

./pm.admin.inc, line 476
List functions for the Project Management module.

Code

function pm_attribute_form($attribute = NULL) {
  $breadcrumb = array();
  $breadcrumb[] = l(t('Project Management'), 'pm');
  $breadcrumb[] = l(t('Attributes'), 'pm/attributes');
  drupal_set_breadcrumb($breadcrumb);
  if (arg(2) == 'add') {
    if (array_key_exists('domain', $_GET) && !isset($attribute->domain)) {
      $attribute->domain = $_GET['domain'];
    }
    if (isset($_SESSION['pmattribute_list_filter']['domain']) && !isset($attribute->domain)) {
      $attribute->domain = $_SESSION['pmattribute_list_filter']['domain'];
    }
  }
  $form = array();
  if (isset($attribute->aid)) {
    $form['aid'] = array(
      '#type' => 'value',
      '#value' => $attribute->aid,
    );
  }
  $form['group1'] = array(
    '#type' => 'markup',
    '#theme' => 'pm_form_group',
  );
  $form['group1']['domain'] = array(
    '#type' => 'textfield',
    '#title' => t('Domain'),
    '#required' => TRUE,
    '#default_value' => isset($attribute->domain) ? $attribute->domain : '',
    '#autocomplete_path' => 'pm/attributes/domain/autocomplete',
    '#size' => 40,
  );
  $domains = array();
  $result = db_select('pmattribute', 'sa')
    ->fields('sa', array(
    'domain',
  ))
    ->orderBy('domain', 'ASC')
    ->distinct()
    ->execute();
  foreach ($result as $i) {
    $domains[$i->domain] = $i->domain;
  }
  $form['group1']['parent_domain'] = array(
    '#type' => 'select',
    '#title' => t('Parent domain'),
    '#required' => FALSE,
    '#default_value' => isset($attribute->parent_domain) ? $attribute->parent_domain : '',
    '#options' => array(
      '' => '-',
    ) + $domains,
  );
  $form['group2'] = array(
    '#type' => 'markup',
    '#theme' => 'pm_form_group',
  );
  $form['group2']['akey'] = array(
    '#type' => 'textfield',
    '#title' => t('Key'),
    '#required' => TRUE,
    '#default_value' => isset($attribute->akey) ? $attribute->akey : '',
    '#size' => 25,
    '#maxlength' => 100,
  );
  $form['group2']['avalue'] = array(
    '#type' => 'textfield',
    '#title' => t('Value'),
    '#required' => TRUE,
    '#default_value' => isset($attribute->avalue) ? $attribute->avalue : '',
    '#size' => 25,
  );
  $form['group2']['weight'] = array(
    '#type' => 'weight',
    '#title' => t('Weight'),
    '#default_value' => isset($attribute->weight) ? $attribute->weight : 0,
  );
  $form['group3'] = array(
    '#type' => 'markup',
    '#theme' => 'pm_form_group',
  );
  $form['group3']['isactive'] = array(
    '#type' => 'checkbox',
    '#title' => t('Active'),
    '#default_value' => isset($attribute->isactive) ? $attribute->isactive : TRUE,
  );
  $form['group3']['isdefault'] = array(
    '#type' => 'checkbox',
    '#title' => t('Default'),
    '#default_value' => isset($attribute->isdefault) ? $attribute->isdefault : FALSE,
  );
  $form['save'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  if (isset($attribute->aid)) {
    $form['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete'),
      '#submit' => array(
        'pmattribute_form_delete',
      ),
    );
  }
  return $form;
}