You are here

function deploy_ui_manage_plan_form in Deploy - Content Staging 7.3

Callback for the flatten plan page.

File

modules/deploy_ui/deploy_ui.pages.inc, line 103
Deploy UI page functions.

Code

function deploy_ui_manage_plan_form($form, &$form_state, $plan) {
  $form = array();
  $form['deploy_plan'] = array(
    '#type' => 'value',
    '#value' => $plan,
  );
  $base_options = [
    -1 => t('Remove'),
    -9999 => t('Keep'),
  ];

  // Get the entity keys from the aggregator.
  $entity_keys = $plan
    ->getEntities();
  foreach ($entity_keys as $entity_key) {

    // Get the entity info and all entities of this type.
    $entity_info = entity_get_info($entity_key['type']);
    if (!empty($entity_info['entity keys']['revision']) && !empty($entity_key['revision_id'])) {
      $entity = entity_revision_load($entity_key['type'], $entity_key['revision_id']);
    }
    else {
      $entity = entity_load_single($entity_key['type'], $entity_key['id']);
    }
    $title = "{$entity_key['type']}:{$entity_key['id']}";
    $label = entity_label($entity_key['type'], $entity);
    if ($label) {
      $title = $label;
    }
    $options = $base_options;
    if ($entity_info['entity keys']['revision']) {
      if (!empty($entity_key['revision_id'])) {
        $title = t('@title (rev:@rev_id)', array(
          '@title' => $title,
          '@rev_id' => $entity_key['revision_id'],
        ));
      }
      $revisions = db_select($entity_info['revision table'], 'tbl')
        ->fields('tbl', [
        $entity_info['entity keys']['revision'],
      ])
        ->condition($entity_info['entity keys']['id'], $entity_key['id'])
        ->condition($entity_info['entity keys']['revision'], $entity_key['revision_id'], '<>')
        ->execute()
        ->fetchCol();
      $options += array_combine($revisions, $revisions);
    }
    $element_key = "{$entity_key['type']}:{$entity_key['id']}:{$entity_key['revision_id']}";
    $form[$element_key] = [
      '#type' => 'select',
      '#title' => $title,
      '#options' => $options,
      '#default_value' => -9999,
    ];
  }
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => 'Update',
  ];
  return $form;
}