You are here

function crm_core_activity_form in CRM Core 7

Form builder for CRM Core Activity forms.

1 string reference to 'crm_core_activity_form'
crm_core_activity_forms in modules/crm_core_activity/crm_core_activity.module
Implements hook_forms().

File

modules/crm_core_activity_ui/crm_core_activity_ui.pages.inc, line 36
User page callbacks for the Activity UI module.

Code

function crm_core_activity_form($form, &$form_state, $activity) {

  // Ensure this include file is loaded when the form is rebuilt from the cache.
  $form_state['build_info']['files'][] = drupal_get_path('module', 'crm_core_activity_ui') . '/crm_core_activity_ui.pages.inc';

  // Get the contact id of who is trying to add the activity.
  if (isset($activity->field_activity_participants[LANGUAGE_NONE]['0'])) {
    $form['contact_id'] = array(
      '#type' => 'value',
      '#value' => arg(1) == 'contact' ? arg(2) : $activity->field_activity_participants[LANGUAGE_NONE]['0']['target_id'],
    );
  }
  $form['title'] = array(
    '#type' => 'textfield',
    '#required' => TRUE,
    '#title' => t('Title'),
    '#default_value' => $activity->title,
  );
  $form['uid'] = array(
    '#type' => 'value',
    '#value' => $activity->uid,
  );
  field_attach_form('crm_core_activity', $activity, $form, $form_state);
  $form['actions'] = array(
    '#type' => 'actions',
  );

  // We add the form's #submit array to this button along with the actual submit
  // handler to preserve any submit handlers added by a form callback_wrapper.
  $submit = array();
  if (!empty($form['#submit'])) {
    $submit += $form['#submit'];
  }
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save Activity'),
    '#submit' => $submit + array(
      'crm_core_activity_form_submit',
    ),
  );

  // Show delete button if entity exists and user has appropriate permission.
  if ($form_state['op'] == 'edit' && entity_access('delete', 'crm_core_activity', $activity)) {
    $form['actions']['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete'),
      '#submit' => array(
        'crm_core_activity_form_submit_delete',
      ),
    );
  }

  // Set title.
  if ($form_state['op'] == 'add') {
    $crm_activity_type = crm_core_activity_types($activity->type);
    drupal_set_title(t('Add new activity @label', array(
      '@label' => $crm_activity_type->label,
    )));
  }

  // We append the validate handler to #validate in case a form callback_wrapper
  // is used to add validate handlers earlier.
  $form['#validate'][] = 'crm_core_activity_form_validate';
  return $form;
}