Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
cpliakas CreditAttribution: cpliakas commentedGreat 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.
Comment #2
drunken monkeyHm, 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.
Comment #3
cpliakas CreditAttribution: cpliakas commentedI 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.
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.
Hope this helps,
Chris
Comment #4
drunken monkeyYes, this seems to be exactly what I need. Thanks!