A question mostly to Chris: As said, I want to write update code so people won't have to manually move their old facets to the new Facet API ones. Now my question, regarding the Facet API: What functions are there to create and save facets in code, what would I have to keep in mind?

Also, I think I'll include this as a form on the old "Facets" tab for each index – any thoughts on that? (Other than that we haven't thought yet about how to solve the clash in ~/index/%/facets when both modules are enabled …)

Comments

cpliakas’s picture

Great question. There was actually a task at #1208326: Add API functions to enable / disable facets which might have some overlap and API functions that can be used. Specifically it allows for enabling facets. Managing facets in code should theoretically work since we are implementing the CTools exportables API, however that needs to be verified as part of the #1147564: Complete configuration in code functionality task.

drunken monkey’s picture

Hm, but these don't seem to allow me to change the facet's settings.
I don't think I need to deal with exportables or the kind. I just need to know what you internally use for saving new/changed facet settings. I also don't know what to use for the "realm" in the functions.
The use case is that I have a search index and an old facet definition, with settings, etc., and I somehow want to get this data into the Facet API.
Digging a bit into the Facet API (UI) code would probably help me there, but I thought you might just know the functions I need to use. They don't need to be simple API functions, more complicated series of calls are no problem either. If you don't remember either and would have to dig, too, then I can do it as well, of course.

cpliakas’s picture

I see what you are saying. So in order to load the settings, use the code below. Note that there are global and realm specific settings.

$realm_settings = $adapter->getFacet($facet)->getSettings($realm);
$global_settings = $adapter->getFacet($facet)->getSettings();

Note that $facet is the return value from facetapi_facet_load(), and $realm is the return value from facetapi_realm_load(). These are simply the individual definition arrays that are defined in the respective hook_facetapi_*_info() implementations.

Then you can modify the settings object as you see fit, most of the stuff you will want to mess with will be in the $settings->settings property. You then pass each object to the CTools API function to save them to the database.

ctools_export_crud_save('facetapi', $realm_settings);
ctools_export_crud_save('facetapi', $global_settings);

Hope this helps,
Chris

drunken monkey’s picture

Status: Active » Fixed

Yes, this seems to be exactly what I need. Thanks!

Status: Fixed » Closed (fixed)

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