You are here

function hook_google_appliance_cluster_list_alter in Google Search Appliance 8

Same name and namespace in other branches
  1. 7 google_appliance.api.php \hook_google_appliance_cluster_list_alter()

Alter the cluster list render array containing related searches.

This hook is invoked after the list render array is constructed and just before it is passed to drupal_render().

Use this to alter the render array properties.

@todo Update as appropriate.

Parameters

array $cluster_list: A renderable array conforming to theme_item_list().

array $cluster_results: The raw cluster results returned via the Google Appliance instance.

See also

google_appliance_get_clusters()

theme_item_list()

Related topics

1 invocation of hook_google_appliance_cluster_list_alter()
google_appliance_get_clusters in src/Service/Search.php
Get related search via the Google Search Appliance clustering service.

File

./google_appliance.api.php, line 89
Hook documentation.

Code

function hook_google_appliance_cluster_list_alter(array &$cluster_list, array $cluster_results) {

  // Add some CSS classes.
  $cluster_list['#attributes']['class'][] = 'foo-list';
  $cluster_list['#items'] = [];

  // Construct a new list of links using the raw results with a custom path.
  foreach ($cluster_results as $cluster) {
    $cluster_list['#items'][] = Link::fromTextAndUrl($cluster['label'], Url::fromUri('search/my/path/' . $cluster['label']))
      ->toString();
  }

  // Change the first item of the list.
  $cluster_list['#items'][0] = '<span>A new item</span>';
}