The 'reset' link is created by 'plain' markup that is then appended using concatenation, to the facet list.
Not only does it not use the Render API but does not allow the markup to be overridden in any way useful.

I propose that the link should be converted into a render array and then applied to the final output array using the '#prefix' property.

A user could then override the link by using:

function hook_search_page_alter(&$page) {
  $facet_api_array_key = 'facetapi_123';

  // Reset link.
  $reset_link = array(
    '#theme' => 'link',
    '#text' => t('Whole Site'),
    // todo: Include the search query string.
    '#path' => current_path(),
    '#options' => array(
      'attributes' => array('class' => array('reset-link')),
      'html' => FALSE,
    ),
  );

  // Update render array.
  $page['sidebar_first'][$facet_api_array_key]['item_bundle']['#prefix'] = render($reset_link);
}

I have created a patch but the path will need to be tweaked to include the keyword search, which by the way can change depending on the view.

Thanks,
Amarjit

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Amarjit created an issue. See original summary.

Amarjit’s picture

Issue summary: View changes
Amarjit’s picture

This would not actually work because the prefix HTML will always remain when clicking on the various filters.
This is because the main markup is replaced on AJAX call but the #prefix content is not.

The only way that this can work as it currently is by using str_replace() on the '#markup' property.

Thus you end up with the following.

--------------
Page Load
--------------
Facet 1
Facet 2

--------------
Click Facet 1
--------------
Reset Filters
Facet 1
Facet 2

--------------
Click Facet 2
--------------
Reset Filters
Reset Filters
Facet 1
Facet 2

In fact, you cannot even preprocess the render array I suggested because the render has already been carried out around line 135 (ajax_widget_links.inc as an example).

Really, this AJAX script needs to pass the the variables into a template, which should then be used for the AJAX call.

Amarjit’s picture

As a quick fix, you can use the settings.php file to override the string. No multi-lingual modules need to be enabled.

$conf['locale_custom_strings_en'][''] = array(
  'Reset filter' => 'Site Wide Search',
);
eugene.ilyin’s picture

Hello

What actually do you want? You want to change the text in the link?

Amarjit’s picture

Exactly Eugene; In my case. However, someone may want to override that link entirely.

eugene.ilyin’s picture

I think that link shouldn't be overriden totally, because it can break this functionality (it's related with JS). But the text maybe should be configurable in the settings form of the facet. I'll think about it.

Thank you.

  • eugene.ilyin committed c5527da on 7.x-3.x
    Issue #2704107 by Amarjit, eugene.ilyin: Reset link should use render...
eugene.ilyin’s picture

Done. Now you can configure text for reset link on the settings form of the facet.
i18n is supported.

eugene.ilyin’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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