You are here

protected function FacetapiFacetProcessor::mapValues in Facet API 7

Same name and namespace in other branches
  1. 6.3 plugins/facetapi/adapter.inc \FacetapiFacetProcessor::mapValues()
  2. 7.2 plugins/facetapi/adapter.inc \FacetapiFacetProcessor::mapValues()

Maps the IDs to human readable values via the facet's mapping callback.

Parameters

array $build: The initialized render array.

Return value

array The initialized render array with mapped values. See the return of FacetapiFacetProcessor::initializeBuild() for the structure of the return array.

1 call to FacetapiFacetProcessor::mapValues()
FacetapiFacetProcessor::process in plugins/facetapi/adapter.inc
Builds the base render array used as a starting point for rendering.

File

plugins/facetapi/adapter.inc, line 1536
Adapter plugin and adapter related classes.

Class

FacetapiFacetProcessor
Builds base render array used as a starting point for rendering.

Code

protected function mapValues(array $build) {
  if ($this->facet['map callback']) {

    // Get available items and active items, invoke the map callback only when
    // there are values to map.
    // NOTE: array_merge() doesn't work here when the values are numeric.
    if ($values = array_unique(array_keys($build + $this
      ->getActiveItems()))) {
      $this->map = call_user_func($this->facet['map callback'], $values, $this->facet['map options']);

      // Normalize all mapped values to a two element array.
      foreach ($this->map as $key => $value) {
        if ($value === NULL) {
          unset($build[$key]);
          continue;
        }
        if (!is_array($value)) {
          $this->map[$key] = array();
          $this->map[$key]['#markup'] = $value;
          $this->map[$key]['#html'] = FALSE;
        }
        if (isset($build[$key])) {
          $build[$key]['#markup'] = $this->map[$key]['#markup'];
          $build[$key]['#html'] = !empty($this->map[$key]['#html']);
        }
      }
    }
  }
  return $build;
}