There is no straightforward way to manage the title of a facet. In one project I am now using a block_alter function, for our facetapi graphs project there is just no straightforward solution to set the title of the graphs by the user.

This patch removes the content ('Filter by') from the theme function, and adds a setting to the widget_links widget for title (with the same defaults). Basically, you can now edit the title of the facet from the facet settings page.

Adding a title attribute to the widget class could be an alternative, as that removes responsibility of displaying the title field from the classes that implement FacetapiWidget.

Comments

batje’s picture

Status: Active » Needs review

we actually did some work on this, didnt we?

cpliakas’s picture

batje,

Thanks for the patch. The easiest way to do this is the set the block title via the core admin interface. Is this not possible because you are using something like Context that doesn't have a block admin interface?

Thanks,
Chris

batje’s picture

We are creating facets as Graphs, and these graphs may render the title as part of the graph.
Secondly, you can not export block titles with features. And lastly, getting from the facet form to the block form is a lot of work for lazy people :-)

cpliakas’s picture

batje,

All three are valid points! I am in favor of this change, and the patch does work as expected. However, let me think a bit about the implementation a bit further just to make sure it is inline with the architecture and other settings of Facet API.

Thanks for the contribution,
Chris

cpliakas’s picture

Status: Needs review » Needs work

Thought about this a little further, and I like the approach you are taking. I also think that the correct API methods are being utilized, so well done fighting through all the code :-)

My big concern is backwards compatibility now that the module has reached a "stable" state, which is the only reason I am marking this as "needs work". I don't want the titles to change unexpectedly after the module is updated, and I wan't people's custom theme hook overrides to still work if they choose not to set the title through the new setting.

A couple of ideas, it might be good to have the "title" key in the FacetapiWidgetLinks::getDefaultSettings() method default to an empty string. That way if people don't set the value then it will default to theme_facetapi_title(). If should be documented in the description of textfield that this is the behavior.

Option #2, we could alternately have a checkbox that says "override default title". If it isn't selected then we can use the theme hook. If selected, the value in the text field could be used and, since there is a checkbox, could default to whatever you think is more user friendly since it doesn't break backwards compatibility. I am also open to other ideas.

Not critical for this patch, but I would also like to see this support token replacements similar to the Current Search Blocks module. We can tackle that later, but if you are ambitious and want to implement it now I am all for it. Also going forward, I am thinking that theme_facetapi_title() should be deprecated in favor on a hook named theme_facetapi_default_title() since that's more descriptive of how it will be used, but again that definitely doesn't have to be tackled in this issue. I just want to type it now so I don't forget about it later.

Thanks,
Chris

markhalliwell’s picture

Title: Add a title to a facet » Override Facet Label
Version: 7.x-2.x-dev » 7.x-1.x-dev
Status: Needs work » Needs review
StatusFileSize
new3.78 KB

Here's an updated patch against the latest 7.x-1.x-dev.

After thinking about this a lot as well, I think #2 is going to be the best way to go. I added the checkbox support and provided a way to override the facet label.

Given that sites have already probably hooked into theme_facetapi_title() to get rid of or alter the prefix "Filter by", I don't think there is really going to be an elegant way to provide "upgrade support". For that reason, I think a separate issue should be created to figure out the "prefix" problem.

In the mean time, I think at the very least overriding the facet label (not title) is important, especially when you have something like: "Term » All parent terms" and you just want it to be "Term".

Also in regards to deprecating theme_facetapi_title(), I don't think that should happen. In FacetAPI Collapsible #1836748-1: Theming hooks break site theme, markup needed to be added to the facet block title so it could show a way to "toggle" the block.

markhalliwell’s picture

After revisiting the code, I realized that adding the checkbox and textbox for overriding the facet label didn't make sense to put in a plugin. I have refactored the code to place it in the main admin settings form. I also added a description to the title override textbox explaining how to to remove or alter the "prefix".

technikh’s picture

other use case is, on default search page.
Core block interface cannot be used to change the titles on default search page.

Browse available categories

Pick a category to launch a search.
eugene.ilyin’s picture

Thank you for your patch, it helped me a lot.

vegardjo’s picture

+1 for this! I actually *have to* use it to solve some other problems related to translation of facetAPI block titles.

I haven't gotten to the bottom of the translation problem, but this is what happens: I have a site in Norwegian and English. Norwegian is the default language, and Norwegian is the base for translations. The field labels (including the fields referencing taxononies used to filter/facet with), are thus also in Norwegian, as they should.

I can translate these labels to English via the translate interface, which work everywhere **exept** in the facetAPI block. These block titles can only be translated from English to Norwegian, not the other way around. So if the field labels are English, all is fine and translatable, but if they are not it's not working.

Seems to me it interprets the original label as English in all cases. It might be related to the "t(filter by @title:)" function, where the text around @title is localizable, but not the @title itself? Or, the source language setting is not repected for the @title.

This is probably a different problem, but the only way I could actually solve it was to use this patch, override the Norwegian field label with an English label, then translate this back to Norwegian again..

vildoc’s picture

Mark, patch works, but still like to be to support in the current search block

vildoc’s picture

Issue summary: View changes
StatusFileSize
new1.4 KB

Status: Needs review » Needs work

The last submitted patch, 12: FacetAPI_facet_block_title_token.patch, failed testing.

Exploratus’s picture

Johann Wagner’s picture

Thanks for patch #7, works great on version 7015.

kopeboy’s picture

Will this be added to a stable release? I am currently translating the Block titles but I wonder if this patch can help also translating the Default option label when using a Single select filter for example.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 12: FacetAPI_facet_block_title_token.patch, failed testing.

cpliakas’s picture

kopeboy, unfortunately this will not be added until a patch is submitted that applied cleanly and passes automated testing.

Thanks,
Chris

The last submitted patch, 7: 1665164-facetapi-override_facet_label-7.patch, failed testing.

dydave’s picture

Status: Needs work » Needs review
StatusFileSize
new4.99 KB

Hi guys,

Quick follow-up on this issue.

Please find attached a re-roll of the patch from #7 against facetapi-7.x-1.x at 316b904 (current HEAD) that hopefully shouldn't be a problem for Automated Tests.
File attached as: facetapi-override_facet_label-1665164-22.patch.

Also, I have added to this patch the logic suggested in the patch from #12, allowing token replacements for Overriden facet labels.

This updated patch certainly needs manual testing, in particular the added tokens.
Feel free to test the settings on the admin form and the expected behavior as well.

Please let me know if you would have any questions on any points/code/aspects mentioned on this updated patch, I would surely be glad to provide more information.

I would greatly appreciate if you could take a bit of time to look into the patch and give me your feedback/opinion on these changes.
Any feedback, testing, changes, recommendations would be highly appreciated.
Thanks in advance to all for your testing, reporting and feedback.

floydm’s picture

Status: Needs review » Reviewed & tested by the community

I've tested that patch #22 applies cleanly to both 7.x-1.5 and 7.x-1.x HEAD, provides the expected functionality, and exports/restores properly via features. Can we mark this RTBC?

dmsmidt’s picture

Great additions, works for me.

flocondetoile’s picture

Patch #22 works fine on 7.x-1.5. Very very useful. Thanks

rschwab’s picture

+1 RTBC. It works as expected, including the new token for the overridden titles appearing in places like the Current Search blocks.

However, I wonder if what cpliakas meant was to have tokens available for use in the overridden titles? If that's the case this isn't yet in the patch.

summit’s picture

Hi,
Would love to have this patch in!
The changing of "by" to "op" in dutch I did with http://www.drupalcontrib.org/api/drupal/contributions!facetapi!facetapi....
Thanks for building this, and please commit.
greetings,
Martijn

knalstaaf’s picture

It seems like I can't get the label (title) translated through the translation UI or the Facet API UI, nor would it adopt the translated vocabulary title for instance. But it is possible by using a regular block title (and make the block translatable), so I guess that's ok.

iamfredrik’s picture

I had to use the following theme function to get the @title translated after applying patch #22:

function theme_facetapi_title($variables) {
return t('Filter by @title:', array('@title' => drupal_strtolower(t($variables['title']))));
}

I had to put a t function inside the code from #28: t($variables['title'])

jsst’s picture

This patch looks good and does what it promises. Should go into the next release!

gunwald’s picture

Works great, please commit.

Cool_Goose’s picture

I've tested the latest 22 patch as well and it works well
+1 for the merge.

vincenzodb’s picture

patch #22 worked also for me
drupal 7.42
facetapi 1.5

thanks

nwom’s picture

#22 works amazingly. I was looking for a way to override the Current Search block and it provided a new title token that did just that. Thank you very much!

sebastien m.’s picture

Works perfectly excepted for "Field group" in Current Search Block.
The token is not suggested, neither replaced.

sebastien m.’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new2.41 KB
new7.04 KB

Here is a patch to add overriden title support for "Field Group" in "Current Search" blocks.

ckng’s picture

Patch #37 works fine, works for Current Search block as well.

jeremylounds’s picture

#37 worked for me.

Also, a note for anyone else trying to change the value in the Current Search block, the token I used successfully was

[facetapi_facet:facet-title]

jeremylounds’s picture

Has anyone tried this with a Field Collection?

Instead of the overwritten title, I get "Filter by Field Collection Title » Field:"

Any ideas? Thank you!

sebastien m.’s picture

@jeremylounds using this patch will add a new field for each facet block which allow you to override the facet title.
so you need to explicitely specify it, otherwise it will fall back to the default behavior.

jeremylounds’s picture

Thank you for the reply, @Actualys

I think my problem was a caching issue, as I have it working now.

donquixote’s picture

The change does not apply to Current search blocks.

donquixote’s picture

Oh, I just realize, one simply needs to change the token to e.g.
[facetapi_active:facet-title]: [facetapi_active:active-value]

nwom’s picture

Status: Needs review » Reviewed & tested by the community

This patch works for me as well. The only two issues that have arisen from users were non-patch related issues (see above). I think it's RTBC.

mikran’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new7.04 KB

The patch didn't apply to current HEAD, here's a reroll

eugene.ilyin’s picture

Status: Needs review » Postponed (maintainer needs more info)

@mikran this thing looks very strange for me

-        $title = filter_xss(token_replace($field_pattern, $data));
+        $title = filter_xss(token_replace($field_pattern, $data, array('adapter' => $adapter)));

Could you explain it please?

mikran’s picture

That code was originally added by Sebastien @Actualys, comment 37 with a note

Here is a patch to add overriden title support for "Field Group" in "Current Search" blocks.

So I'd imagine it has something to do with "Field Group".

eugene.ilyin’s picture

Status: Postponed (maintainer needs more info) » Needs work

Mhh, for me it looks like a mistake according to the documentation of function token_replace.
Key "adapter" is not supported. Maybe adapter should be added into the $data.
But okay I'll allocate time to finalize this issue soon.

Thank you @mikran.

eugene.ilyin’s picture

I have committed it. Also, I think that if the facet title will be overridden, it should be translated through i18n, but I don't want to delay current issue. I'll create a separate issue for i18n.

eugene.ilyin’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.