added js library to edlp_search

This commit is contained in:
Bachir Soussi Chiadmi
2018-03-19 00:20:14 +01:00
parent ff495add52
commit 973483a6eb
4 changed files with 34 additions and 3 deletions
@@ -0,0 +1,10 @@
(function ($, Drupal, drupalSettings) {
var settings = drupalSettings.edlp_studio;
function init(){
console.log('Edlp Search Init');
};
init();
})(jQuery, Drupal, drupalSettings);
@@ -0,0 +1,6 @@
edlp_search-library:
js:
assets/js/edlp_search.js: { scope: footer }
dependencies:
- core/drupalSettings
- core/jquery
@@ -6,6 +6,7 @@
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
/**
* Implements hook_help().
@@ -23,6 +24,17 @@ function edlp_search_help($route_name, RouteMatchInterface $route_match) {
}
}
/**
* Implements hook_page_attachments().
* @param array $attachments
*/
function edlp_search_page_attachments(array &$attachments) {
$attachments['#attached']['library'][] = 'edlp_search/edlp_search-library';
$url = Url::fromRoute('edlp_search.edlp_search_controller_searchResults_ajax', [], ['absolute' => TRUE]);
$attachments['#attached']['drupalSettings']['edlp_search']['results_ajax_url'] = $url->getInternalPath();
}
/**
* Implements hook_theme().
*/
@@ -5,8 +5,7 @@ namespace Drupal\edlp_search\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\EntityStorageInterface;
// use Drupal\facets\FacetManager\DefaultFacetManager;
// use Drupal\search_api_page\Entity\SearchApiPage;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\Form\FormBuilder;
use Symfony\Component\HttpFoundation\JsonResponse;
@@ -88,10 +87,14 @@ class EdlpSearchController extends ControllerBase {
'#markup' => $this->t('Implement method: searchResults')
];
}
public function searchResultsJson(){
public function searchResultsJson(Request $request){
$keys = $request->query->get('keys');
$response = new JsonResponse();
$response->setData([
'test'=>'search results',
'keys'=>$keys
// 'rendered'=> $rendered,
]);
return $response;