0

I am trying to change the markup of links created by the facetapi module. The theme function is here

function theme_facetapi_link_inactive($variables) {
  $accessible_vars = array(
    'text' => $variables['text'],
    'active' => FALSE,
  );
  $accessible_markup = theme('facetapi_accessible_markup', $accessible_vars);
  $sanitize = empty($variables['options']['html']);
  $variables['text'] = ($sanitize) ? check_plain($variables['text']) : $variables['text'];
  if (isset($variables['count'])) {
    $variables['text'] .= ' ' . theme('facetapi_count', $variables);
  }
  $variables['text'] .= $accessible_markup;
  $variables['options']['html'] = TRUE;
  return theme_link($variables);
}

I am trying to override this function so I can change the markup without editing the module files. I've tried MYTHEME_preprocess_facetapi_link_inactive and using a custom module but both times I can print the variables and they are correct but the links are still displayed wrong.

function MYTHEME_preprocess_facetapi_link_inactive($variables) {
  $accessible_vars = array(
    'text' => $variables['text'],
    'active' => FALSE,
  );
  $accessible_markup = theme('facetapi_accessible_markup', $accessible_vars);
  $sanitize = empty($variables['options']['html']);
  $variables['text'] = ($sanitize) ? check_plain($variables['text']) : $variables['text'];
  if (isset($variables['count'])) {
    $variables['text'] .= ' <strong>' . theme('facetapi_count', $variables) . '!!!</strong>';
  }
  $variables['text'] .= $accessible_markup;
  $variables['options']['html'] = TRUE;
  return theme_link($variables);
}

Am I going about this the wrong way?

1

You're nearly there, but a preprocess function doesn't look applicable to what you're trying to do. A preprocess function is used to set up variables for a theme function, not to actually produce the markup.

What it looks like you're trying to do is to override theme_facetapi_link_inactive() completely, in which case you don't use a preprocess function, but instead you call the function MYTHEME_theme_function_name() and the theme engine will use that instead of the original function.

So all you need to is change the name of your function like so:

function MYTHEME_facetapi_link_inactive($variables) {
  // Same code as in your example
}

After you clear the caches Drupal will start using that function in place of theme_facetapi_link_inactive() whenever it's called.

  • Thank you so much, I had attempted that function but I hadn't cleared the cache between changing it from preprocess. That was just what I needed. Thank you! – user1289347 Aug 27 '12 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.