You are here

function facetapi_widgets_get in Facet API 6

Invokes hook_facetapi_widget_info(), returns all defined widgets.

Parameters

$variables: An array of variables passed to the restriction callbacks. By default it contains the adapter, realm definition, and facet definition. If the array is empty, all widgets will be returned.

$reset: A boolean flagging whether the static should be reset.

Return value

An associative array of widget definitions keyed by widget name.

2 calls to facetapi_widgets_get()
FacetapiFacet::build in ./facetapi.adapter.inc
Returns the facet's render array.
facetapi_facet_settings_form in ./facetapi.admin.inc
Returns settings for an individual facet that apply to a realm.

File

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

Code

function facetapi_widgets_get(array $variables = array(), $reset = FALSE) {
  static $widgets;
  if (NULL === $widgets || $reset) {

    // Gets widgets from hooks, merges with defaults.
    $widgets = array();
    foreach (module_implements('facetapi_widget_info') as $module) {
      $module_widgets = module_invoke($module, 'facetapi_widget_info');
      foreach ($module_widgets as $widget_name => $widget_info) {
        $defaults = array(
          'title' => t('Widget'),
          'callback' => 'facetapi_links_widget_callback',
          'widget requirements' => array(),
          'variables' => array(),
          'weight' => 0,
          'file' => '',
          'file path' => drupal_get_path('module', $module),
        );
        $widgets[$widget_name] = array_merge($defaults, $widget_info);
      }
    }

    // Allows modules to alter the widget defintions.
    drupal_alter('facetapi_widget_info', $widgets);
  }

  // If variables passed, returns widgets the facet has access to.
  if (!empty($variables)) {
    $return = $widgets;
    foreach ($widgets as $widget_name => $widget_info) {
      $return[$widget_name]['variables'] = array_merge($variables, $widgets[$widget_name]['variables']);
    }
    return array_filter($return, 'facetapi_widgets_filter');
  }
  else {
    return $widgets;
  }
}