0

I'm trying to do something that seems fairly basic, but I'm having loads of trouble.

The drupal search_form block outputs an input field and a submit button, in that order. I'd like to swap the order of those fields. I'm using theme_preprocess_search_block_form to attempt to reverse the order. This is my current function:

function mytheme_preprocess_search_block_form(&$data)
{

    $data['form']['search_block_form']['#attributes']['placeholder'] = 'Search ...';
    $data['form'] = array_reverse($data['form']);
    foreach(element_children($data['form']) as $k) {
        if(!empty($data['form'][$k]['#weight'])) {
            $data['form'][$k]['#weight'] *= -1;
        }
    }

    $data['form']['#sorted'] = FALSE;
}

This function does get called, since a var_dump will output to the browser, however, the changes don't make it to the front end. So, what is unchanging my changes?

1 Answer 1

0

I figured this out. Drupal can be so infuriating when you are new to it.

The rendering of the search_form_block was happening in a template function file:

bootstrap-search-form-wrapper.func.php.

containing:

function bootstrap_bootstrap_search_form_wrapper($variables)

The function customizes the rendering of the search form by calling out elements specifically - thus ignoring '#weight'; the wrapper function is part of the bootstrap theme.

The solution is to overwrite the bootstrap theme function with a similar function in our child theme: function mytheme_bootstrap_search_form_wrapper($variables)

o.O

Hopefully this helps someone.

2
  • once you can, you should mark your own answer as the accepted answer so this doesn't keep showing up as unanswered
    – Geoff
    Commented May 18, 2014 at 6:12
  • Thanks for the reminder, SE wouldn't let me until 2 days after asking for some reason. Commented May 19, 2014 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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