You are here

function pmpapi_groups_edit_form in Public Media Platform API Integration 7

Form constructor for the PMPAPI edit groups form.

See also

pmpapi_groups_edit_form_submit()

1 string reference to 'pmpapi_groups_edit_form'
pmpapi_groups_menu in pmpapi_groups/pmpapi_groups.module
Implements hook_menu().

File

pmpapi_groups/pmpapi_groups.admin.inc, line 63
Basic admin forms, validators, and submit handlers.

Code

function pmpapi_groups_edit_form($form, &$form_state, $guid = '') {
  if ($guid) {
    $group = pmpapi_fetch_group($guid);
    $form['guid'] = array(
      '#type' => 'hidden',
      '#value' => $guid,
    );
  }
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Group name'),
    '#default_value' => !empty($group->attributes->title) ? $group->attributes->title : '',
    '#disabled' => (bool) $guid,
    '#required' => TRUE,
  );
  $pmp = new PMPAPIDrupal();
  $pmp
    ->pull(array(
    'limit' => 1000,
    'profile' => 'organization',
    'searchsort' => 'title',
  ));
  $possible_orgs = array();
  foreach ($pmp->query->results->docs as $doc) {
    $possible_orgs[$doc->attributes->guid] = $doc->attributes->title;
  }
  $selected_orgs = array();
  if (!empty($group->items)) {
    foreach ($group->items as $item) {
      $selected_orgs[] = $item->attributes->guid;
    }
  }
  $form['orgs'] = array(
    '#type' => 'select',
    '#multiple' => TRUE,
    '#required' => TRUE,
    '#title' => t('Add organizations'),
    '#options' => $possible_orgs,
    '#default_value' => $selected_orgs,
  );

  // Submit Button.
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save Group'),
  );
  return $form;
}