Open Data Catalog v2.0.0
FacetsCommonTrait.php
Go to the documentation of this file.
1 <?php
2 
4 
10 trait FacetsCommonTrait {
11 
21  private function getValuesFromCommaSeparatedString(string $string): array {
22  return array_map('trim', str_getcsv($string));
23  }
24 
36  private function getFacetsTypes(array $params): array {
37  $facetsTypes = [];
38  $approvedFacetsTypes = ['theme', 'keyword', 'publisher__name'];
39 
40  if (isset($params['facets']) && is_string($params['facets'])) {
41  $facetsTypes = $this->getValuesFromCommaSeparatedString($params['facets']);
42  }
43 
44  // If no specific facet types were requested, returned all approved facet
45  // types.
46  if (empty($facetsTypes)) {
47  return $approvedFacetsTypes;
48  }
49 
50  // Make sure that facet types given are part of the approved list.
51  return array_filter($facetsTypes, function ($facetsType) use ($approvedFacetsTypes) {
52  return in_array($facetsType, $approvedFacetsTypes);
53  });
54  }
55 
56 }
Drupal\metastore_search