You are here

function revision_scheduler_field_attach_form in Revision scheduler 7

Implements hook_field_attach_form().

File

./revision_scheduler.module, line 751

Code

function revision_scheduler_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode) {

  // Try to detect if this really is an entity edit / add form, if not skip
  // further processing. Unfortunately taxonomy term has a naming inconsistency
  // thus we need a special handling for it.
  $form_entity_type = $entity_type;
  if ($form_entity_type == 'taxonomy_term') {
    $form_entity_type = 'term';
  }
  if (!isset($form_state[$form_entity_type])) {
    return;
  }
  list($entity_id, $revision_id) = entity_extract_ids($entity_type, $entity);
  $form['revision_scheduler'] = array(
    '#type' => 'fieldset',
    '#title' => t('Revision scheduler'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#group' => 'additional_settings',
    '#attributes' => array(
      'class' => array(
        'entity-form-revision-scheduler',
      ),
    ),
    '#weight' => 21,
    '#access' => revision_scheduler_operation_create_access($entity_type, $entity, NULL),
    '#tree' => TRUE,
    '#parents' => array_merge($form['#parents'], array(
      'revision_scheduler',
    )),
  );

  // Pass the form into the edit form to get most of the form elements.
  $operation = new stdClass();
  $operation->id = NULL;
  $operation->entity_type = $entity_type;
  $operation->entity_id = $entity_id;
  $operation->revision_id = $revision_id;
  $operation->operation = NULL;
  $operation->uid = $GLOBALS['user']->uid;
  form_load_include($form_state, 'inc', 'revision_scheduler', 'revision_scheduler.pages');
  $form_state_clone = $form_state;
  $form_state_clone['build_info']['args'] = array(
    $operation,
    $entity,
  );
  $form['revision_scheduler'] = revision_scheduler_edit_form($form['revision_scheduler'], $form_state_clone, $operation, $entity);

  // Tweak the form elements.
  $form['revision_scheduler']['revision_id']['#access'] = FALSE;
  $form['revision_scheduler']['operation']['#required'] = FALSE;
  $form['revision_scheduler']['operation']['#empty_option'] = t('- None -');
  unset($form['revision_scheduler']['actions']);

  // Allow the revision fieldset form elements to be altered using
  // hook_form_revision_scheduler_edit_form_alter().
  drupal_alter('form_revision_scheduler_edit_form', $form['revision_scheduler'], $form_state_clone);
}