You are here

function search_api_saved_searches_activate_page in Search API Saved Searches 7

Page callback that activates a saved search.

This is mostly necessary for anonymous users, but also when a user enters a different mail address than the one he registered with.

Parameters

SearchApiSavedSearch $search: The search to activate.

string $key: The secret access key for this search, used to authenticate the user.

1 string reference to 'search_api_saved_searches_activate_page'
search_api_saved_searches_menu in ./search_api_saved_searches.module
Implements hook_menu().

File

./search_api_saved_searches.pages.inc, line 139
User UI functions and form callbacks for saved searches.

Code

function search_api_saved_searches_activate_page(SearchApiSavedSearch $search, $key) {
  $ret = array(
    'message' => array(
      '#markup' => '',
    ),
    'link' => array(
      '#markup' => '<p>' . $search
        ->l(t('View this saved search')) . '</p>',
    ),
  );
  if ($search->enabled) {
    $msg = t('This saved search has already been activated.');
  }
  else {
    $search->enabled = TRUE;
    $success = $search
      ->save();
    if (!$success) {
      drupal_set_message(t('An error occurred while trying to activate the search. Please contact the site administrator.'), 'error');
      return $ret;
    }
    $msg = t('Your saved search was successfully activated.');
  }
  if ($search->notify_interval >= 0) {
    $msg .= ' ' . t('You will receive e-mail notifications for new results in the future.');
  }
  $ret['message']['#markup'] = '<p>' . $msg . '</p>';
  return $ret;
}