I need to change some default behavior from the facet API.

I am searching for documentation about the hook from the Facet API module, but I have not found anything for now, except a very good tutorial about Apache Solr and Facet API.

I downloaded the Facet API bonus module because I thought it would help me.

There are some very good features like Rewrite facet items via callback function, but it seems it only works for the markup; I can't change the input.

function custom_facet_facet_items_alter(&$build, &$settings) {
  if ($settings->facet == "field_produit_dev_durable") {
    foreach($build as $key => $item) {
      $build[$key]["#markup"] = drupal_strtoupper($item["#markup"]);

I tried to use the Devel modutle o see the content of the variables build, and setting, but there is nothing interesting for me.

My facets now

What I want

So I need two things

  • Understand how to change the checkbox input
  • Understand how to remove the count number aside the Yes or No

I made my module and use this, but weirdly it doesn't remove the number.

$build[$key]["#markup"] = drupal_strtoupper($item["#markup"]);

I used the fist tutorial I linked at the beginning of my post, but I found a problem I don't understand.

When I used my code on two different facets I got an error:

An illegal choice has been detected. Please contact the site administrator.

My code is the same code shown in this article, but I replace the select field with a radio field. I think there is a conflict between the two form, when I validate.

2 Answers 2


What you're doing to change the markup should just work, here's a working example I have from a project that does just that:

function foo_facet_items_alter(&$build, &$settings) {
  if ($settings->facet === 'my_facet') {
    foreach($build as $key => $item) {
      $build[$key]["#markup"] = drupal_ucfirst($item["#markup"]);

I can confirm that it works as expected.

As far as switching the select for a radio, the error you get is pretty common and you're probably not removing/adding extra Form API options that aren't allowed for one of the types.

Radio buttons behave a bit different than selects, you might not be able to just switch the #type and have it work, if this is still relevant, please post the code you're using to alter that form... thanks!


On this page you find a paragraph about creating a custom facet api widget:


  • This article was linked in the OP. Jun 5, 2015 at 2:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.