You are here

function purge_item_action_form in Purge 7.2

Form for simple yes/no operations on items.

1 string reference to 'purge_item_action_form'
purge_menu in ./purge_ui.module
Implements hook_menu().

File

includes/purge_ui.inc, line 585
Provides administrative interface for the Purge module.

Code

function purge_item_action_form($form, &$form_state, $item_type, $item_name, $action) {

  // Get the bundle and the item.
  $bundle = new PurgePurgerBundleUI();
  $item = $bundle->{$item_type}[$item_name];
  if ($action == 'delete') {
    $actioned = t('deleted');

    // Check if we have access to delete this item.
    if (in_array(PURGE_ACCESS_FULL, $item->access)) {
      $access = TRUE;

      // Check if something bad happens is this item is deleted.
      unset($bundle->{$item_type}[$item_name]);
    }
  }
  else {

    // Unkown action. Throw warming and redirect to main admin view.
    drupal_set_message(t('Unkown action'), 'error');
    $form_state['redirect'] = 'admin/config/system/purge';
    return;
  }

  // Now make sure we have access.
  if (!$access) {
    drupal_set_message(t('Action not allowed'), 'warning');
    $form_state['redirect'] = 'admin/config/system/purge';
    return;
  }
  else {

    // Check if there would be errors after this action.
    $errors = $bundle
      ->validate();
    if (count($errors) > 0) {

      // Display this warming:
      $message = t('If you confirm to @action @item_type @item_name your current configuration will no longer be valid.' . ' See these warmings:', array(
        '@action' => $action,
        '@item_type' => $bundle->type[$item_type]->name,
        '@item_name' => $item->name,
      ));

      // Dispaly each error message.
      foreach ($errors as $error) {
        $message = $message . '<br>' . $error;
      }
      drupal_set_message($message, 'warning');
    }

    // Display the question if there are errors or the action is delete.
    if (count($errors) > 0 || $action == 'delete') {
      $form = array();
      $form['action'] = array(
        // Hidden fields to save arguments in form state.
        'item_type' => array(
          '#type' => 'hidden',
          '#default_value' => $item_type,
        ),
        'item_name' => array(
          '#type' => 'hidden',
          '#default_value' => $item_name,
        ),
        'action' => array(
          '#type' => 'hidden',
          '#default_value' => $action,
        ),
        'question' => array(
          '#type' => 'item',
          '#markup' => t('Are you sure you want to @action the @item_type @item_name ?', array(
            '@action' => t($action),
            '@item_type' => $bundle->type[$item_type]->name,
            '@item_name' => $item->name,
          )),
        ),
        'confirm' => array(
          '#type' => 'submit',
          '#value' => t('Confirm'),
          '#submit' => array(
            'purge_item_action_form_submit',
          ),
        ),
        'cancel' => array(
          '#type' => 'submit',
          '#name' => 'cancel',
          '#value' => t('Cancel'),
          '#submit' => array(
            'purge_form_button_callback',
          ),
        ),
      );
    }
  }
  return $form;
}