You are here

function facetapi_save_facet_status in Facet API 6.3

Same name and namespace in other branches
  1. 7.2 facetapi.module \facetapi_save_facet_status()
  2. 7 facetapi.module \facetapi_save_facet_status()

Sets the facet status in a given realm, stores settings in the database.

Parameters

FacetapiAdapter $adapter: The adapter object of the searcher the settings are being modified for.

array $realm: The realm definition as returned by facetapi_realm_load().

array $facet: The facet definition as returned by facetapi_facet_load().

$status: Flags whether or not the facet is being enabled or disabled.

$weight: If the realm is sortable, allows the assigning of a weight. Pass FALSE to maintain the previously stored value.

$batch_process: A boolean flagging whether batch processing is being performed. If set to TRUE, the caches and statics won't be reset.

Return value

TRUE if the operation succeeded, FALSE otherwise.

3 calls to facetapi_save_facet_status()
facetapi_realm_settings_form_submit in ./facetapi.admin.inc
Form submission handler for facetapi_realm_settings_form().
facetapi_save_facet_disabled in ./facetapi.module
Disables a facet in a given realm, stores settings in the database.
facetapi_save_facet_enabled in ./facetapi.module
Enables a facet in a given realm, stores settings in the database.

File

./facetapi.module, line 1165
An abstracted facet API that can be used by various search backends.

Code

function facetapi_save_facet_status(FacetapiAdapter $adapter, array $realm, array $facet, $status, $weight, $batch_process) {

  // Loads the realm settings, sets enabled flag and weight.
  $settings = $adapter
    ->getFacet($facet)
    ->getSettings($realm);
  $settings->enabled = $status ? 1 : 0;
  if (FALSE !== $weight) {
    $settings->settings['weight'] = $realm['sortable'] ? $weight : 0;
  }

  // Saves the settings in the database, stores the result.
  // NOTE: CTools export componenet loaded in the getSettings() method.
  $success = FALSE !== ctools_export_crud_save('facetapi', $settings);

  // Clears caches and statics if we are not batch processing.
  if ($success && !$batch_process) {
    ctools_static('facetapi_get_enabled_facets', array(), TRUE);
    static $enabled_facets;
    $enabled_facets = NULL;
    if ('block' == $realm['name']) {
      cache_clear_all(NULL, 'cache_block');
      cache_clear_all('facetapi:delta_map', 'cache');
    }
  }
  return $success;
}