You are here

function bynder_generate_facets in Bynder 7

Generate facets.

1 call to bynder_generate_facets()
bynder_generate_search in includes/bynder.browser.inc
Generate search page.

File

includes/bynder.browser.inc, line 510
Manages the Bynder media browser functionality

Code

function bynder_generate_facets($facets, $selected_facets) {
  global $filter_labels;
  if (empty($facets)) {
    return array();
  }
  $facets_list = array(
    '#theme' => 'item_list',
    '#type' => 'ul',
    '#title' => t('Filters'),
    '#prefix' => '<div class="normal-facet-list-wrapper">',
    '#suffix' => '</div>',
    '#attributes' => array(
      'class' => 'normal_facet_list facet_list',
    ),
  );
  foreach ($facets as $facet_category_name => $facet_category) {
    if ($facet_category_name == 'type' || $facet_category_name == 'categoryId' || $facet_category_name == 'subBrandId') {
      continue;
    }

    //Hide single item filters.
    if (count($facet_category) < 2) {
      continue;
    }
    if (!isset($filter_labels[$facet_category_name])) {
      $filter_labels[$facet_category_name] = t($facet_category_name);
    }
    $icons = array(
      'brandId' => 'archive',
      'tags' => 'tags',
      'type' => 'file',
      'orientation' => 'image',
    );
    $children = bynder_generate_facets_link($facet_category, $facet_category_name, $selected_facets);
    $facet_category = array(
      'data' => "<span><i class='fa fa-" . filter_xss(isset($icons[$facet_category_name]) ? $icons[$facet_category_name] : 'caret-right') . "'></i> " . filter_xss($filter_labels[$facet_category_name]) . "<span class='expand'><i class='fa fa-angle-down'></i></span></span>",
      'id' => preg_replace('/\\s+/', '-', $facet_category_name),
      'class' => array(
        'facet_title',
      ),
      'children' => $children,
    );
    if (count($children)) {
      $facets_list['#items'][] = $facet_category;
    }
  }
  return $facets_list;
}