I am trying to parse my form's GET method and create a function that can get all the parameters from the URL in DRUPAL 8. I have a form that I am gonna use it to filter my library items as search( I know I can use search api or advanced search but my client wants this way ) So I have a few fields such as keyword, title, description, location, author, from, to, collection. and when I add all the fields after the redirection to result page
http://example.com/advancedsearchresult?keyword=test1&title=test2&description=test3&author=test4&location=test5&from=&to=&collection=&media=all
I would like to do nice job with using OOP and Symfony service features. My question is how could i create a function in my controller for this result page that is gonna parse all the parameters from the URL so I can use them to create an object in service to create individual query for each parameters to make search mechanism for this form?
UPDATED:
After @oknate pointed out, I updated my controller like this:
namespace Drupal\advancedsearch\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\advancedsearch\AdvancedSearchQuery;
class SearchResultController extends ControllerBase {
protected $advancedsearchSearchResult;
public function __construct(AdvancedSearchQuery $advancedsearch_search_result ) {
$this->advancedsearchSearchResult = $advancedsearch_search_result;
}
public static function create(ContainerInterface $container) {
return new static(
$container->get('advancedsearch.search.result')
);
}
private function setupAdvancedSearchQuery() {
$params = \Drupal::request()->query->all();
foreach ($params as $key => $value) {
if (!empty($value)) {
$params[$key] = $value;
}
}
}
}
on the other hand, I created my service file, I created my variables which matches with parameters, so am I gonna be able to use setupAdvancedSearchQuery() when I call the object for each parameters, if so can anyone give a hint?