-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add searchform partial and function to replace default WordPress functionality #2090
Conversation
… WordPress functionality
@@ -1,7 +1,7 @@ | |||
<form role="search" method="get" class="search-form" action="{{ esc_url( home_url( '/' ) ) }}"> | |||
<form role="search" method="get" class="search-form" action="{{ esc_url(home_url( '/') ) }}"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See commit d93964b -- this was already done
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is "sf" descriptive enough?
I'm not super attached to it, I just cut it down because I felt like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good here.
Could just use |
IMO |
true |
So yay? |
🚀 |
Would it make more sense to put the $sf_* stuff in the app controller? Out of the box, Sage seems slightly more oriented towards using that approach. Though I think the docs introduce filters as the easy way, the code itself emphasizes the controller more, and I think most discussion on Discourse focuses on them too. No strong feelings, just raising the question. Other than that, LGTM. Thanks all! |
My reason for the filter approach is that it's the "native" approach—Controller is a 3rd party package. IMO if we offer a "native" way to do a thing then our most basic implementation should use that implementation, not depend on a 3rd party package. |
That makes sense to me. TBH I thought it was odd that Sage uses the controller out of the box and not the data filters (to the extent it uses either) for the same reason. Could just be because |
app/filters.php
Outdated
$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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return $data + [
'sf_action' => esc_url(home_url('/')),
// etc...
];
That will preserve sf_*
key-value pairs that are already present in the $data
array and only merge them in if they don't already exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be all set
Need to fix indenting to pass phpcs. Line 87 has 1 space, should be 0; the rest should use 4-space indents rather than 2. |
So, yay? |
Inspired by this thread:
https://discourse.roots.io/t/custom-search-form/9079
The WordPress searchform, and the ability to customize it, is basic WP functionality that Sage unintentionally breaks. This PR predictably replaces the WP default template with a Blade partial, much like the the comments partials we already ship, letting users use get_search_form() as normal.