1

I am using the 7.x-3.0 version of Bootstrap and have sub themed it. I want to change wrapped div, add 'input-group-sm' to the class bit I can't not figure out how to override it. if I add search-block-form.tpl.php to my sub theme I can access and alter that but the code I need is in bootstrap-search-form-wrapper-func.php I have copied that to my sub theme with no success. I have tried replicating the same file structure as Bootstrap 'mytheme/theme/bootstrap/bootstrap-search-form-wrapper.func.php', I have tried putting just in my templates dir.

My last attempt was trying to follow the instructions on theme registry alters: https://www.drupal.org/node/2224003 which I have as this:

function CFbootstrap_theme(&$existing, $type, $theme, $path) {
  $hooks['CFbootstrap_hook'] = array(
    'CFbootstrap_search_form_wrapper' => array(
      'render element' => 'element',
    ),
  );

  bootstrap_hook_theme_complete($existing, $theme, $path . '/theme');
  return $hooks;
}

Nothing works, what I am doing wrong? How do I override this *.func.php?

2

OK, I have this figured out, I think I just got confused by instructions and getting ramped up again on the ways of Drupal. Anyway just to leave a clear answer. All subthemes will be called MYTHEME. In my template.php in my subtheme I altered the form and then added hook to my new form wrapper:

function MYTHEME_form_alter(&$form, &$form_state, $form_id) {
if($form_id) {
    switch ($form_id) {
        case 'search_form':
            dpm($form);
            $form['basic']['keys']['#theme_wrappers'] = array('MYTHEME_search_form_wrapper');
            break;
    }
  }
}

function MYTHEME_theme(&$existing, $type, $theme, $path) {
  $hooks = array(
      'MYTHEME_search_form_wrapper' => array(
      'render element' => 'element',
      'file' => 'MYTHEME-search-form-wrapper.func.php',
    ),
  );

  return $hooks;
}

In this I copied the original wrapper file and made my changes, you could just copy the method and add it to your template.php anyway here's that method, referenced earlier as 'MYTHEME-search-form-wrapper.func.php':

function MYTHEME_MYTHEME_search_form_wrapper($variables) {
  $output = '<div class="input-group input-group-sm">';
  $output .= $variables['element']['#children'];
  $output .= '<span class="input-group-btn">';
  $output .= '<button type="submit" class="btn btn-default">';
  // We can be sure that the font icons exist in CDN.
  if (theme_get_setting('bootstrap_cdn')) {
    $output .= _bootstrap_icon('search');
  }
  else {
    $output .= t('Search');
  }
  $output .= '</button>';
  $output .= '</span>';
  $output .= '</div>';
  return $output;
}

Key here is having the subtheme name twice in the method call. The instructions I found on this didn't give an explanation on why that needs to be. I'll try to find relevant information.

  • This works, but it only addresses the form on the search results page. It does affect the search block, but I get two search buttons. – Hawkee Apr 11 '16 at 17:46
  • I suggest you mark your own answer as "accepted" (so that it is no longer considered as "unanswered"). – Pierre.Vriens Oct 28 '17 at 17:40
0

The array structure is wrong, since it should be the following.

  $hooks['CFbootstrap_search_form_wrapper'] = array(
    'render element' => 'element',
  );

What they show as 'theme_key' doesn't mean '<put here your theme short name>_key' but '<put here the theme function name>'. See for example the implementation of hook_theme() done from the Node module, which contains the following code.

 return array(
    'node' => array(
      'render element' => 'elements',
      'template' => 'node',
    ),
    'node_search_admin' => array(
      'render element' => 'form',
    ),

    // …
  );

Notice also that calling bootstrap_hook_theme_complete($existing, $theme, $path . '/theme') is not anymore necessary with the Bootstrap theme 7.x-3.1.

  • function CFbootstrap_theme(&$existing, $type, $theme, $path) { $hooks['search_block_form'] = array ( 'render element' => 'form', 'file' => 'theme/search/search-block-form.tpl.php', ); $hooks['bootstrap_search_form_wrapper'] = array( 'render element' => 'element', 'file' => 'theme/bootstrap/bootstrap-search-form-wrapper.func.php', ); bootstrap_hook_theme_complete($existing, $theme, $path . '/theme'); return $hooks; } This now pulls a different search form all together. Not the bootstrap or my sub theme? PS I'm on 7.x-3.0. – pandabrand Jul 1 '15 at 18:45
  • I have upgraded to 7.x-3.1-beta2 also removed my hook_theme function and just copied the files to my sub theme and used blocks. Using theme debugger I can see that it's using the form template I copied but it's still not using the func.php that I copied. Do I not understand this or is this a bug? Serious questions because I am at a loss with this. – pandabrand Jul 1 '15 at 19:18

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.