You are here

function sarnia_form_search_api_admin_confirm_alter in Sarnia 7

Implements hook_form_FORM_ID_alter().

Don't allow deleting indexes or servers until the associated Sarnia entity type is deleted.

File

./sarnia.module, line 1086

Code

function sarnia_form_search_api_admin_confirm_alter(&$form, &$form_state) {
  if ($form['type']['#value'] == 'index' && $form['action']['#value'] == 'delete') {
    $index = $form_state['build_info']['args'][2];
    if (($entity_type = sarnia_entity_type_load($index->machine_name)) && $entity_type['search_api_server'] == $index->server) {
      $form['info'] = array(
        '#type' => 'container',
        'info' => array(
          '#markup' => t("This index is created and managed by Sarnia. It will be deleted only when the Sarnia entity type is deleted. You can manage the Sarnia entity type by visiting the !link.", array(
            '!link' => l(t('the server configuration section'), "admin/config/search/search_api/server/{$index->server}/sarnia"),
          )),
        ),
      );
      $form['message']['#access'] = FALSE;
      $form['description']['#access'] = FALSE;
      $form['confirm']['#access'] = FALSE;
      $form['actions']['#access'] = FALSE;
    }
  }
  elseif ($form['type']['#value'] == 'server' && $form['action']['#value'] == 'delete') {
    $server = $form_state['build_info']['args'][2];
    if ($server->class == 'sarnia_solr_service') {
      $sarnia_type = sarnia_entity_server_name_load($server->machine_name);
      if ($sarnia_type) {

        // Don't allow deleting 'till the Sarnia type is deleted.
        $form['info'] = array(
          '#type' => 'container',
          'info' => array(
            '#markup' => t("This Search API Server has a Sarnia entity type enabled. Please delete the Sarnia entity type before deleting the server. You can manage the Sarnia entity type by visiting the !link.", array(
              '!link' => l(t('the Sarnia configuration tab'), "admin/config/search/search_api/server/{$server->machine_name}/sarnia"),
            )),
          ),
        );
        $form['message']['#access'] = FALSE;
        $form['description']['#access'] = FALSE;
        $form['confirm']['#access'] = FALSE;
        $form['actions']['#access'] = FALSE;
      }
    }
  }
}