Display Yes/No instead 0/1 on boolean facet filters

Public

By default the boolean fields' value displayed as 0/1 on facet filters. We could easily change this by using a custom value callback for these fields.

</> CopyGet raw version
php
  1. <?php
  2.  
  3. /**
  4.  * Implements hook_facetapi_facet_info_alter().
  5.  */
  6. function MY_MODULE_facetapi_facet_info_alter(array &$facet_info, array $searcher_info) {
  7. $facet_info = array_map(function($facet) {
  8. if ($facet['field type'] == 'boolean') {
  9. $facet['map options']['value callback'] = '_MY_MODULE_facetapi_boolean_facet_filter_value_callback';
  10. }
  11. return $facet;
  12. }, $facet_info);
  13. }
  14.  
  15. /**
  16.  * Custom value callback for boolean facet filters.
  17.  */
  18. function _MY_MODULE_facetapi_boolean_facet_filter_value_callback(array $values, array $options) {
  19. return array_map(function($value) {
  20. return $value ? t('Yes') : t('No');
  21. }, $values);
  22. }