Set the title of a facet API block in hook_update_n

Public

</> CopyGet raw version
php
  1. function MY_MODULE_update_7003(&$sandbox) {
  2. $facet_blocks = array(
  3. array(
  4. 'title' => 'Clients', // <-- the desired title of the block
  5. 'searcher' => 'search_api@default_node_index',
  6. 'realm_name' => 'block',
  7. 'facet_name' => 'field_client', // <-- the name of the indexed field
  8. ),
  9. );
  10.  
  11. foreach ($facet_blocks as $facet_block) {
  12. $delta = facetapi_build_delta($facet_block['searcher'], $facet_block['realm_name'], $facet_block['facet_name']);
  13. $hash = facetapi_hash_delta($delta);
  14. db_query('UPDATE block SET title = :title WHERE module = :facetapi AND delta = :delta', array(':facetapi' => 'facetapi', ':delta' => $hash, ':title' => $facet_block['title']));
  15. }
  16. }

Comments

mxr576's picture

db_query() should/could be replaced with db_update(), but anyway, thanks for the code! :)

  1. db_update('block')
  2. ->condition('module', 'facetapi')
  3. ->condition('delta', $hash)
  4. ->fields(array('title' => $facet_block['title']))
  5. ->execute();