You are here

function search_api_admin_confirm in Search API 7

Form constructor for a generic confirmation form.

Parameters

$type: The type of entity (not the real "entity type"). Either "server" or "index".

$action: The action that would be executed for this entity after confirming. One of "reindex" ("index" type only), "clear", "disable" or "delete".

Entity $entity: The entity for which the action would be performed. Must have a "name" property.

Return value

array|false Either a form array, or FALSE if this combination of type and action is not supported.

3 string references to 'search_api_admin_confirm'
search_api_admin_index_view in ./search_api.admin.inc
Page callback for displaying an index's status.
search_api_admin_server_view in ./search_api.admin.inc
Page callback: Displays information about a server.
search_api_menu in ./search_api.module
Implements hook_menu().

File

./search_api.admin.inc, line 2252
Administration page callbacks for the Search API module.

Code

function search_api_admin_confirm(array $form, array &$form_state, $type, $action, Entity $entity) {
  switch ($type) {
    case 'server':
      switch ($action) {
        case 'clear':
          $text = array(
            t('Clear server @name', array(
              '@name' => $entity->name,
            )),
            t('Do you really want to clear all indexed data from this server?'),
            t('This will permanently remove all data currently indexed on this server. Before the data is reindexed, searches on the indexes associated with this server will not return any results. This action cannot be undone. <strong>Use with caution!</strong>'),
            t("The server's indexed data was successfully cleared."),
          );
          break;
        case 'disable':
          $text = array(
            t('Disable server @name', array(
              '@name' => $entity->name,
            )),
            t('Do you really want to disable this server?'),
            t('This will disconnect all indexes from this server and disable them. Searches on these indexes will not be available until they are added to another server and re-enabled. All indexed data (except for read-only indexes) on this server will be cleared.'),
            t('The server and its indexes were successfully disabled.'),
          );
          break;
        case 'delete':
          if ($entity
            ->hasStatus(ENTITY_OVERRIDDEN)) {
            $text = array(
              t('Revert server @name', array(
                '@name' => $entity->name,
              )),
              t('Do you really want to revert this server?'),
              t('This will revert all settings for this server back to the defaults. This action cannot be undone.'),
              t('The server settings have been successfully reverted.'),
            );
          }
          else {
            $text = array(
              t('Delete server @name', array(
                '@name' => $entity->name,
              )),
              t('Do you really want to delete this server?'),
              t('This will delete the server and disable all associated indexes. ' . "Searches on these indexes won't be available until they are moved to another server and re-enabled."),
              t('The server was successfully deleted.'),
            );
          }
          break;
        default:
          return FALSE;
      }
      break;
    case 'index':
      switch ($action) {
        case 'reindex':
          $text = array(
            t('Re-index index @name', array(
              '@name' => $entity->name,
            )),
            t('Do you really want to queue all items on this index for re-indexing?'),
            t('This will mark all items for this index to be marked as needing to be indexed. Searches on this index will continue to yield results while the items are being re-indexed. This action cannot be undone.'),
            t('The index was successfully marked for re-indexing.'),
          );
          break;
        case 'clear':
          $text = array(
            t('Clear index @name', array(
              '@name' => $entity->name,
            )),
            t('Do you really want to clear the indexed data of this index?'),
            t('This will remove all data currently indexed for this index. Before the data is reindexed, searches on the index will not return any results. This action cannot be undone.'),
            t('The index was successfully cleared.'),
          );
          break;
        case 'disable':
          $text = array(
            t('Disable index @name', array(
              '@name' => $entity->name,
            )),
            t('Do you really want to disable this index?'),
            t("Searches on this index won't be available until it is re-enabled."),
            t('The index was successfully disabled.'),
          );
          break;
        case 'delete':
          if ($entity
            ->hasStatus(ENTITY_OVERRIDDEN)) {
            $text = array(
              t('Revert index @name', array(
                '@name' => $entity->name,
              )),
              t('Do you really want to revert this index?'),
              t('This will revert all settings on this index back to the defaults. This action cannot be undone.'),
              t('The index settings have been successfully reverted.'),
            );
          }
          else {
            $text = array(
              t('Delete index @name', array(
                '@name' => $entity->name,
              )),
              t('Do you really want to delete this index?'),
              t('This will remove the index from the server and delete all settings. ' . 'All data on this index will be lost.'),
              t('The index has been successfully deleted.'),
            );
          }
          break;
        default:
          return FALSE;
      }
      break;
    default:
      return FALSE;
  }
  $form = array(
    'type' => array(
      '#type' => 'value',
      '#value' => $type,
    ),
    'action' => array(
      '#type' => 'value',
      '#value' => $action,
    ),
    'id' => array(
      '#type' => 'value',
      '#value' => $entity->machine_name,
    ),
    'message' => array(
      '#type' => 'value',
      '#value' => $text[3],
    ),
  );
  $desc = "<h3>{$text[1]}</h3><p>{$text[2]}</p>";
  return confirm_form($form, $text[0], "admin/config/search/search_api/{$type}/{$entity->machine_name}", $desc);
}