View source
<?php
function commerce_recurring_ui_types_overview() {
$header = array(
t('Entity Type'),
t('Operations'),
);
$rows = array();
foreach (commerce_recurring_types() as $type) {
$recurring_entity_type = ucfirst(strtr($type, '_', ' '));
$links = menu_contextual_links('commerce-recurring-entity-type', 'admin/commerce/recurring-entities/types', array(
strtr($type, array(
'_' => '-',
)),
));
$rows[] = array(
t('@recurring_entity_type', array(
'@recurring_entity_type' => $recurring_entity_type,
)),
theme('links', array(
'links' => $links,
'attributes' => array(
'class' => 'links inline operations',
),
)),
);
}
if (empty($rows)) {
$rows[] = array(
array(
'data' => t('There are no recurring entity types yet.'),
'colspan' => 2,
),
);
}
return theme('table', array(
'header' => $header,
'rows' => $rows,
));
}
function commerce_recurring_ui_entity_type_redirect($type) {
drupal_goto('admin/commerce/recurring-entities/types/' . strtr($type, '_', '-') . '/fields');
}
function commerce_recurring_edit_product_form($form, &$form_state, $recurring_entity, $op = 'edit') {
$form['start_date'] = array(
'#type' => 'date_popup',
'#title' => t('Start date'),
'#default_value' => !empty($recurring_entity->start_date) ? date('Y-m-d H:i:s', $recurring_entity->start_date) : NULL,
'#weight' => -3,
'#required' => TRUE,
'#date_year_range' => '-0:+10',
'#date_format' => 'Y-m-d',
);
$form['due_date'] = array(
'#type' => 'date_popup',
'#title' => t('Due date'),
'#default_value' => !empty($recurring_entity->due_date) ? date('Y-m-d H:i:s', $recurring_entity->due_date) : NULL,
'#weight' => -2,
'#required' => TRUE,
'#date_year_range' => '-1:+10',
'#date_format' => 'Y-m-d',
);
$form['end_date'] = array(
'#type' => 'date_popup',
'#title' => t('End date'),
'#default_value' => !empty($recurring_entity->end_date) ? date('Y-m-d H:i:s', $recurring_entity->end_date) : NULL,
'#weight' => -1,
'#date_format' => 'Y-m-d',
);
$owner = user_load($recurring_entity->uid);
$form['uid'] = array(
'#title' => t('Recurring entity user'),
'#type' => 'textfield',
'#autocomplete_path' => 'user/autocomplete',
'#default_value' => $owner->name,
'#required' => TRUE,
);
$form_state['commerce_recurring'] = $recurring_entity;
field_attach_form('commerce_recurring', $recurring_entity, $form, $form_state);
$form['status'] = array(
'#type' => 'radios',
'#title' => t('Status'),
'#options' => array(
0 => t('Disabled'),
1 => t('Enabled'),
),
'#default_value' => $recurring_entity->status,
'#weight' => 35,
'#required' => TRUE,
);
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save recurring entity'),
'#weight' => 40,
);
return $form;
}
function commerce_recurring_edit_product_form_validate(&$form, &$form_state) {
$dates = array(
'start_date',
'due_date',
'end_date',
);
foreach ($dates as $date) {
if (is_array($form_state['values'][$date])) {
if (!empty($form_state['values'][$date]['date'])) {
form_set_value($form[$date], strtotime($form_state['values'][$date]['date']), $form_state);
}
else {
form_set_error($date, t('Date can\'t be null'));
}
}
else {
form_set_value($form[$date], strtotime($form_state['values'][$date]), $form_state);
}
}
if ($owner = user_load_by_name($form_state['values']['uid'])) {
form_set_value($form['uid'], $owner->uid, $form_state);
}
else {
form_set_error('uid', t('The specified user doesn\'t exist'));
}
}
function commerce_recurring_edit_product_form_submit(&$form, &$form_state) {
$recurring_entity = entity_ui_form_submit_build_entity($form, $form_state);
$recurring_entity
->save();
$form_state['redirect'] = 'admin/commerce/recurring-entities';
}
function commerce_recurring_ui_delete_confirm_form($form, &$form_state, $recurring_entity) {
$form_state['recurring_entity'] = $recurring_entity;
$form['#submit'][] = 'commerce_recurring_entity_delete_form_submit';
$form = confirm_form($form, t('Are you sure you want to delete this recurring entity?'), '', '<p>' . t('Deleting this recurring entity cannot be undone.') . '</p>', t('Delete'), t('Cancel'), 'confirm');
return $form;
}
function commerce_recurring_entity_delete_form_submit($form, &$form_state) {
$recurring_entity = $form_state['recurring_entity'];
if ($recurring_entity
->delete()) {
drupal_set_message(t('Commerce recurring entity has been deleted.'));
}
else {
drupal_set_message(t('Commerce recurring entity could not be deleted.'), 'error');
}
$form_state['redirect'] = 'admin/commerce/recurring-entities';
}