function revision_scheduler_edit_form in Revision scheduler 7
2 calls to revision_scheduler_edit_form()
2 string references to 'revision_scheduler_edit_form'
- revision_scheduler_add_form in ./
revision_scheduler.pages.inc - revision_scheduler_menu in ./
revision_scheduler.module - Implements hook_menu().
File
- ./
revision_scheduler.pages.inc, line 134
Code
function revision_scheduler_edit_form($form, &$form_state, $operation, $entity = NULL) {
$form['id'] = array(
'#type' => 'value',
'#value' => $operation->id,
);
$form['entity_type'] = array(
'#type' => 'value',
'#value' => $operation->entity_type,
);
$form['entity_id'] = array(
'#type' => 'value',
'#value' => $operation->entity_id,
);
$form['uid'] = array(
'#type' => 'value',
'#value' => $operation->uid,
);
$parents = isset($form['#parents']) ? $form['#parents'] : array();
$operation_parents = array_merge($parents, array(
'operation',
));
$operation_state_name = $operation_parents[0];
if (count($operation_parents) > 1) {
$operation_state_name .= '[' . implode('][', array_slice($operation_parents, 1)) . ']';
}
if ($revision_id = drupal_array_get_nested_value($form_state, array_merge(array(
'values',
), $parents, array(
'revision_id',
)))) {
$operation->revision_id = $revision_id;
}
$revision_ids = revision_scheduler_get_all_entity_revision_ids($operation->entity_type, $operation->entity_id);
$revisions = revision_scheduler_entity_revision_load_multiple($operation->entity_type, $operation->entity_id, $revision_ids);
krsort($revisions);
if (empty($entity) && !empty($operation->revision_id) && !empty($revisions[$operation->revision_id])) {
$entity = $revisions[$operation->revision_id];
}
$wrapper = 'revision-scheduler-operation-wrapper-' . $operation->entity_type . '-' . (int) $operation->entity_id . '-' . (int) $operation->id;
$form['revision_id'] = array(
'#type' => 'select',
'#title' => t('Revision'),
'#options' => array(),
'#default_value' => $operation->revision_id,
'#required' => TRUE,
'#ajax' => array(
'callback' => 'revision_scheduler_update_operation_options',
'wrapper' => $wrapper,
'method' => 'replace',
'effect' => 'fade',
),
);
foreach ($revisions as $revision_id => $revision) {
$form['revision_id']['#options'][$revision_id] = t('Revision @id: @label', array(
'@id' => $revision_id,
'@label' => entity_label($operation->entity_type, $revision),
));
}
$form['operation'] = array(
'#prefix' => '<div id="' . $wrapper . '">',
'#suffix' => '</div>',
'#type' => 'select',
'#title' => t('Scheduled operation'),
'#options' => revision_scheduler_entity_revision_operation_get_options($operation->entity_type, $entity),
'#default_value' => $operation->operation,
'#required' => TRUE,
'#attributes' => array(
'class' => array(
'revision-scheduler-operation',
),
),
);
$date_format = variable_get('revision_scheduler_date_pattern', 'Y-m-d H:i');
$form['time_scheduled'] = array(
'#type' => 'textfield',
'#title' => t('Scheduled date'),
'#default_value' => !empty($operation->time_scheduled) ? format_date($operation->time_scheduled, 'custom', $date_format) : '',
'#description' => t('Format: %time. The timezone is %timezone.', array(
'%time' => format_date(REQUEST_TIME, 'custom', $date_format),
'%timezone' => drupal_get_user_timezone(),
)),
'#element_validate' => array(
'revision_scheduler_validate_time_scheduled',
),
'#attributes' => array(
'class' => array(
'revision-scheduler-time-scheduled',
),
),
'#states' => array(
'invisible' => array(
':input[name="' . $operation_state_name . '"]' => array(
'value' => '',
),
),
'optional' => array(
':input[name="' . $operation_state_name . '"]' => array(
'value' => '',
),
),
),
);
if (module_exists('date_popup')) {
$form['time_scheduled']['#type'] = 'date_popup';
$form['time_scheduled']['#date_format'] = $date_format;
$form['time_scheduled']['#date_year_range'] = '0:+5';
$form['time_scheduled']['#date_increment'] = 5;
}
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Schedule'),
);
if (!isset($_GET['destination']) && !empty($operation->entity_id) && ($uri = entity_uri($operation->entity_type, $entity))) {
$_GET['destination'] = $uri['path'];
}
$form['actions']['cancel'] = array(
'#type' => 'link',
'#title' => t('Cancel'),
'#href' => '<front>',
'#weight' => 10,
);
if (isset($_GET['destination'])) {
$url = drupal_parse_url(urldecode($_GET['destination']));
$form['actions']['cancel']['#href'] = $url['path'];
if (!empty($url['query'])) {
$form['actions']['cancel']['#options']['query'] = $url['query'];
}
}
return $form;
}