View source
<?php
function crm_core_contact_ui_form_wrapper($contact) {
return drupal_get_form('crm_core_contact_ui_form', $contact);
}
function crm_core_contact_ui_add_page() {
drupal_set_title(t('Add a contact'));
$item = menu_get_item();
$types = crm_core_contact_types(TRUE);
$content = array();
foreach ($types as $type) {
$_content = menu_get_item($item['href'] . '/' . $type->type);
if ($_content['access']) {
$content[] = $_content;
}
}
if (count($content) == 1) {
$item = array_shift($content);
drupal_goto($item['href']);
}
return theme('crm_core_contact_ui_add_list', array(
'content' => $content,
));
}
function crm_core_contact_entity_ui_get_form_wrapper($type) {
$values = array(
'type' => $type,
);
$contact = entity_create('crm_core_contact', $values);
return drupal_get_form('crm_core_contact_ui_form', $contact);
}
function crm_core_contact_ui_form($form, &$form_state, $contact) {
$form_state['build_info']['file'] = drupal_get_path('module', 'crm_core_contact_ui') . '/crm_core_contact_ui.pages.inc';
$form_state['crm_core_contact'] = $contact;
field_attach_form('crm_core_contact', $contact, $form, $form_state);
$form['actions'] = array(
'#type' => 'actions',
);
$submit = array();
if (!empty($form['#submit'])) {
$submit += $form['#submit'];
}
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => crm_core_contact_ui_save_contact_button_name($contact->type),
'#submit' => $submit + array(
'crm_core_contact_ui_form_submit',
),
);
if (!empty($contact->contact_id) && entity_access('delete', 'crm_core_contact', $contact)) {
$form['actions']['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete'),
'#submit' => array(
'crm_core_contact_ui_form_submit_delete',
),
);
}
$form['#validate'][] = 'crm_core_contact_ui_form_validate';
return $form;
}
function crm_core_contact_ui_form_validate($form, &$form_state) {
$contact = $form_state['crm_core_contact'];
field_attach_form_validate('crm_core_contact', $contact, $form, $form_state);
}
function crm_core_contact_ui_form_submit($form, &$form_state) {
global $user;
$create = FALSE;
$contact =& $form_state['crm_core_contact'];
if (empty($contact->contact_id)) {
$contact->uid = $user->uid;
$create = TRUE;
}
field_attach_submit('crm_core_contact', $contact, $form, $form_state);
crm_core_contact_save($contact);
drupal_set_message(t('Contact saved.'));
$form_state['redirect'] = $create ? 'crm-core/contact' : "crm-core/contact/{$contact->contact_id}";
}
function crm_core_contact_ui_form_submit_delete($form, &$form_state) {
$destination = array();
if (isset($_GET['destination'])) {
$destination = drupal_get_destination();
unset($_GET['destination']);
}
$contact = $form_state['crm_core_contact'];
$uri = entity_uri('crm_core_contact', $contact);
$form_state['redirect'] = array(
$uri['path'] . '/delete',
array(
'query' => $destination,
),
);
}
function crm_core_contact_ui_delete_form($form, &$form_state, $contact) {
$form['contact_id'] = array(
'#type' => 'value',
'#value' => $contact->contact_id,
);
return confirm_form($form, t("Are you sure want to delete '@name' contact?", array(
'@name' => crm_core_contact_title($contact),
)), 'crm-core/contact/' . $contact->contact_id, $description = NULL, $yes = t('Yes'), $no = t('No'));
}
function crm_core_contact_ui_delete_form_submit($form, &$form_state) {
if (crm_core_contact_delete($form_state['values']['contact_id'])) {
drupal_set_message(t('Contact deleted.'));
}
$form_state['redirect'] = 'crm-core/contact';
}
function crm_core_contact_ui_delete_form_validate($form, &$form_state) {
}
function crm_core_contact_ui_revision_form($contact) {
$revisions = crm_core_contact_ui_revision_list($contact);
var_dump($revisions);
$form['placeholder'] = array(
'#markup' => 'This is a placeholder for now.',
);
return $form;
}
function crm_core_contact_ui_revert_form($form, &$form_state, $contact, $vid) {
$form['vid'] = array(
'#type' => 'value',
'#value' => $vid,
);
$form_state['crm_core_ui']['contact'] = $contact;
return confirm_form($form, t("Are you sure want to revert this contact?"), 'crm-core/contact/' . $contact->contact_id . '/revisions', 'Reverting the contact will result in a new revision being created', t('Yes'), t('Cancel'));
}
function crm_core_contact_ui_revert_form_submit($form, &$form_state) {
$contact = $form_state['crm_core_ui']['contact'];
if (crm_core_contact_revert($contact, $form_state['values']['vid'])) {
drupal_set_message(t('Contact reverted.'));
}
$form_state['redirect'] = 'crm-core/contact/' . $contact->contact_id . '/revisions';
}