Bladeren bron

added js library to edlp_search

Bachir Soussi Chiadmi 6 jaren geleden
bovenliggende
commit
973483a6eb

+ 10 - 0
sites/all/modules/figli/edlp_search/assets/js/edlp_search.js

@@ -0,0 +1,10 @@
+(function ($, Drupal, drupalSettings) {
+
+  var settings = drupalSettings.edlp_studio;
+
+  function init(){
+    console.log('Edlp Search Init');
+  };
+
+  init();
+})(jQuery, Drupal, drupalSettings);

+ 6 - 0
sites/all/modules/figli/edlp_search/edlp_search.libraries.yml

@@ -0,0 +1,6 @@
+edlp_search-library:
+  js:
+    assets/js/edlp_search.js: { scope: footer }
+  dependencies:
+    - core/drupalSettings
+    - core/jquery

+ 12 - 0
sites/all/modules/figli/edlp_search/edlp_search.module

@@ -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().
  */

+ 6 - 3
sites/all/modules/figli/edlp_search/src/Controller/EdlpSearchController.php

@@ -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;