Extract logic from search form template

This removes all logic from the search form Blade template, and extracts
it to the "Controller" level via Sage's filter system. It also adds a
global 'app' filter to hook into, so that the search form data will be
served on every page.
This commit is contained in:
Ben
2018-08-06 13:06:34 -07:00
parent b41047f5a1
commit e898cf1f4d
2 changed files with 21 additions and 4 deletions

View File

@@ -13,6 +13,11 @@ add_filter('body_class', function (array $classes) {
}
}
/** Add a global class to everything.
* We want it to come first, so stuff its filter does can be overridden.
*/
array_unshift($classes, 'app');
/** Add class if sidebar is active */
if (display_sidebar()) {
$classes[] = 'sidebar-primary';
@@ -75,3 +80,15 @@ add_filter('comments_template', function ($comments_template) {
add_filter('get_search_form', function () {
return template('partials.searchform');
});
/**
* Collect data for searchform.
*/
add_filter('sage/template/app/data', function ($data) {
$data['sf_action'] = esc_url(home_url('/'));
$data['sf_screen_reader_text'] = _x('Search for:', 'label', 'sage');
$data['sf_placeholder'] = esc_attr_x('Search …', 'placeholder', 'sage');
$data['sf_current_query'] = get_search_query();
$data['sf_submit_text'] = esc_attr_x('Search', 'submit button', 'sage');
return $data;
});