i need to overwrite the twig template for the input field of my search block. it is now being generated via the template input--form-control.html.twig. I would like to use the available suggestion input--search.html.twig but as long as Bootstrap is designated as my base theme in my info.yml file this suggestion is not possible to use. however, once i remove bootstrap as a base theme and test it, the suggestion becomes immediately available with my sub-theme. how can i fix this? thanks.

CommentFileSizeAuthor
#6 abstract_methodize-2838071-6.patch14.34 KBmarkhalliwell

Comments

drupalstrap created an issue. See original summary.

markhalliwell’s picture

Status: Active » Closed (works as designed)

You need to implement a @BootstrapAlter plugin in your sub-theme:


namespace Drupal\THEMENAME\Plugin\Alter;

use Drupal\bootstrap\Utility\Unicode;
use Drupal\bootstrap\Utility\Variables;

/**
 * Implements hook_theme_suggestions_alter().
 *
 * @BootstrapAlter("theme_suggestions")
 */
class ThemeSuggestions extends \Drupal\bootstrap\Plugin\Alter\ThemeSuggestions {

  /**
   * {@inheritdoc}
   */
  public function alter(&$suggestions, &$context1 = NULL, &$hook = NULL) {
    $variables = Variables::create($context1);
    // Ignore "input__search", otherwise let base theme handle suggestions.
    if (Unicode::strpos($variables['theme_hook_original'], 'input__search') === FALSE) {
      parent::alter($suggestions, $context1, $hook);
    }
  }

}
markhalliwell’s picture

Title: Bootstrap does not allow using a template name suggestion for input--form-control.html.twig » Append passed theme hook suggestions
Version: 8.x-3.1 » 8.x-3.x-dev
Category: Bug report » Feature request
Status: Closed (works as designed) » Active

Actually, I suppose we could parse $variables['theme_hook_original'] and append them to the suggestion provided, like is done for links__dropbutton, e.g. input__form_control__search.

edit: the above is an easy workaround until this can be implemented though.

pyxio’s picture

thanks Mark. i create ThemeSuggestion.php in my subtheme with the code provided and i am still not getting the suggestion available to me. what might i be doing wrong? cheers

markhalliwell’s picture

Title: Append passed theme hook suggestions » Abstract/methodize theme hook suggestion alterations

This entire alter hook needs to be refactored TBH. I'll upload a patch here shortly for you to test.

markhalliwell’s picture

Status: Active » Needs review
Issue tags: +Needs change record
StatusFileSize
new14.34 KB
markhalliwell’s picture

Title: Abstract/methodize theme hook suggestion alterations » Allow ThemeSuggestion to be more dynamic

Better title

markhalliwell’s picture

Issue tags: -Needs change record

I've gone ahead and created a CR for this as well: https://www.drupal.org/node/2838155

pyxio’s picture

good morning

i applied this patch and theme suggestion is still not working. just to be sure i handled the part in my subtheme correctly ... i create a file located at src/Plugin/Alter/ThemeSuggestions.php which contains the code in #2 (of course i changed THEMENAME to the name of my sub-theme. Is this correct? Cheers

markhalliwell’s picture

Ignore #2, just apply the patch in #6.

The theme hook suggestion that should work now is:
input--form-control--search.html.twig

pyxio’s picture

awesome. indeed it does! do i still need to keep src/Plugin/Alter/ThemeSuggestions.php in my sub-themes? thanks so much for quickly addressing this and for all your contributions in general to this great drupal theme. cheers

markhalliwell’s picture

Status: Needs review » Reviewed & tested by the community

do i still need to keep src/Plugin/Alter/ThemeSuggestions.php in my sub-themes?

No, not unless you need to add/remove/change any suggestions (which it doesn't sound like you do).

thanks so much for quickly addressing this and for all your contributions in general to this great drupal theme.

You're quite welcome :D Just glad to help provide a solid base theme.

  • markcarver committed 716005a on 8.x-3.x
    Issue #2838071 by markcarver, drupalstrap: Allow ThemeSuggestion to be...
markhalliwell’s picture

Status: Reviewed & tested by the community » Fixed
markhalliwell’s picture

Title: Allow ThemeSuggestion to be more dynamic » Allow ThemeSuggestions:alter() to be more dynamic

Typo in title (for prosperity sake) and expanded to include method (for searchability sake).

markhalliwell’s picture

Title: Allow ThemeSuggestions:alter() to be more dynamic » Allow ThemeSuggestions::alter() to be more dynamic

Ugh, too tired.

pyxio’s picture

gotta love the attention to detail ;o) now for some well deserved rest! cheers

Status: Fixed » Closed (fixed)

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