materio_search_api.module 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. <?php
  2. /**
  3. * @file
  4. * This is the file description for Materiobasemod module.
  5. *
  6. * In this more verbose, multi-line description, you can specify what this
  7. * file does exactly. Make sure to wrap your documentation in column 78 so
  8. * that the file can be displayed nicely in default-sized consoles.
  9. */
  10. // define(MATERIO_SEARCH_API_RESULTS_PATH, 'explore');
  11. /**
  12. * Implements hook_permission().
  13. */
  14. function materio_search_api_permission() {
  15. return array(
  16. 'use materio search api' => array(
  17. 'title' => t('Use materio search api'),
  18. 'description' => t('Use materio search api.'),
  19. ),
  20. 'use materio search api for breves' => array(
  21. 'title' => t('Use materio search api for breves'),
  22. 'description' => t('Use materio search api for breves.'),
  23. ),
  24. 'use materio search api autocomplete' => array(
  25. 'title' => t('Use materio search api autocomplete'),
  26. 'description' => t('Use materio search api autocomplete.'),
  27. ),
  28. 'use materio search api viewmode selection' => array(
  29. 'title' => t('Use materio search api viewmode selection'),
  30. 'description' => t('Use materio search api viewmode selection.'),
  31. ),
  32. 'administer materio_search_api' => array(
  33. 'title' => t('administer Materio search api'),
  34. 'description' => t('Administer materio search api.'),
  35. ),
  36. 'use materio search api filters' => array(
  37. 'title' => t('use Materio search api filters'),
  38. 'description' => t('Use materio search api filters.'),
  39. ),
  40. );
  41. }
  42. /**
  43. * Implements hook_menu().
  44. */
  45. function materio_search_api_menu() {
  46. $items = array();
  47. $base = array(
  48. 'type' => MENU_CALLBACK,
  49. 'file' => 'materio_search_api.pages.inc',
  50. );
  51. $items['admin/config/search/search_api/materiosearchapi'] = array(
  52. 'title' => 'Materio Search Api',
  53. 'page callback' => 'drupal_get_form',
  54. 'page arguments' => array('materio_search_api_settings'),
  55. 'access arguments' => array('administer materio_search_api'),
  56. 'file' => 'materio_search_api.admin.inc',
  57. 'type' => MENU_LOCAL_TASK,
  58. );
  59. $items['materiosearchapi/autocomplete/dbselect'] = $base+array(
  60. 'access arguments' => array('use materio search api autocomplete'),
  61. 'page callback' => 'materio_search_api_autocomplete_dbselect',
  62. );
  63. $items['materiosearchapi/autocomplete/searchapi'] = $base+array(
  64. 'access arguments' => array('use materio search api autocomplete'),
  65. 'page callback' => 'materio_search_api_autocomplete_searchapi',
  66. );
  67. $items['explore'] = $base+array(
  68. // 'access arguments' => array('use materio search api'),
  69. 'access callback' => 'materio_search_api_access_search',
  70. 'page callback' => 'materio_search_api_results_search',
  71. 'title' => t('Explore'),
  72. //'page argument' => array(1,2,3),
  73. );
  74. $items['actuality'] = $base+array(
  75. // 'access arguments' => array(),
  76. 'page callback' => 'materio_search_api_actuality',
  77. // 'page argument' => array(),
  78. 'access callback' => TRUE,
  79. );
  80. $items['materiosearchapi/viewmode/change'] = $base+array(
  81. 'access arguments' => array('use materio search api viewmode selection'),
  82. 'page callback' => 'materio_search_api_viewmode_change',
  83. 'page argument' => array(3),
  84. );
  85. return $items;
  86. }
  87. function materio_search_api_access_search(){
  88. return user_access('use materio search api for breves') || user_access('use materio search api');
  89. }
  90. /**
  91. * Implements hook_search_api_data_type_info().
  92. *
  93. * Declare our new type to Search API so it can be selected for a field.
  94. */
  95. function materio_search_api_search_api_data_type_info() {
  96. return array(
  97. 'edge_n2_kw_text' => array(
  98. 'name' => t('Fulltext (partial)'),
  99. 'fallback' => 'text',
  100. ),
  101. );
  102. return $types;
  103. }
  104. /**
  105. * Implements hook_search_api_solr_dynamic_field_info().
  106. *
  107. * Tell Search API Solr how to index our new data type.
  108. */
  109. function materio_search_api_search_api_solr_dynamic_field_info() {
  110. return array(
  111. 'edge_n2_kw_text' => array(
  112. 'prefix' => 'tem',
  113. 'always multiValued' => TRUE,
  114. ),
  115. );
  116. }
  117. /**
  118. * hook_entity_property_info_alter().
  119. */
  120. function materio_search_api_entity_property_info_alter(&$info){
  121. // dsm($info, 'hook_entity_property_info_alter | info');
  122. // watchdog('materio solr', 'materio_search_api_entity_property_info_alter', array());
  123. $properties = &$info['node']['properties'];
  124. for ($i=1; $i <= 5 ; $i++) {
  125. $properties['materio_search_api_taxonomy_term_'.$i] = array(
  126. 'type'=>'taxonomy_term',
  127. 'label'=> t('Main taxonomy term '.$i),
  128. // 'query callback'=>'entity_metadata_table_query',
  129. 'getter callback'=>'materio_search_api_get_main_taxonomy_term_'.$i,
  130. );
  131. }
  132. // $properties['materio_search_api_taxonomy_term_'.$i] = array(
  133. // 'type'=>'list<taxonomy_term>',
  134. // 'label'=> t('Taxonomy term after 5 mains'),
  135. // // 'query callback'=>'entity_metadata_table_query',
  136. // 'getter callback'=>'materio_search_api_get_taxonomy_terms_after_5',
  137. // );
  138. // return $properties;
  139. $company_term_props = &$info['taxonomy_term']['bundles']['company']['properties'];
  140. $company_term_props['country'] = array(
  141. 'label' => t("Country"),
  142. 'description' => t("Company's Country get from tode node."),
  143. 'type' => 'text',
  144. 'getter callback' => 'company_term_property_country_get_props',
  145. );
  146. }
  147. function materio_search_api_get_main_taxonomy_term_1($item){
  148. // dsm($item, 'item');
  149. // watchdog('materio solr', 'materio_search_api_get_taxonomy_term_1', array());
  150. return materio_search_api_get_onto_term($item, 0);
  151. }
  152. function materio_search_api_get_main_taxonomy_term_2($item){
  153. // dsm($item, 'item');
  154. return materio_search_api_get_onto_term($item, 1);
  155. }
  156. function materio_search_api_get_main_taxonomy_term_3($item){
  157. // dsm($item, 'item');
  158. return materio_search_api_get_onto_term($item, 2);
  159. }
  160. function materio_search_api_get_main_taxonomy_term_4($item){
  161. // dsm($item, 'item');
  162. return materio_search_api_get_onto_term($item, 3);
  163. }
  164. function materio_search_api_get_main_taxonomy_term_5($item){
  165. // dsm($item, 'item');
  166. return materio_search_api_get_onto_term($item, 4);
  167. }
  168. function materio_search_api_get_onto_term($item, $delta){
  169. // dsm($item, 'item');
  170. // dsm($delta, 'delta');
  171. if(isset($item->field_onthologie['und'][$delta]))
  172. return taxonomy_term_load($item->field_onthologie['und'][$delta]['tid']);
  173. return null;
  174. }
  175. function company_term_property_country_get_props($term){
  176. // dsm($term, 'company_term_property_country_get_props : term');
  177. if( $node = company_get_tode_node($term) ){
  178. // $field_values = field_get_items('node',$node,'field_public_address');
  179. // dsm($field_values, 'field_values');
  180. $output = rip_tags(render(field_view_field('node',$node,'field_public_address')));
  181. // dsm($output, 'output');
  182. return $output;
  183. }
  184. return null;
  185. }
  186. function company_get_tode_node($term){
  187. if(module_exists('tode'))
  188. if( $entitys = tode_get_nids_from_term($term))
  189. if(isset($entitys['node']))
  190. foreach ($entitys['node'] as $nid => $n)
  191. return node_load($nid);
  192. return false;
  193. }
  194. function rip_tags($string) {
  195. // ----- remove HTML TAGs -----
  196. $string = preg_replace ('/<[^>]*>/', ' ', $string);
  197. // ----- remove control characters -----
  198. $string = str_replace("\r", '', $string); // --- replace with empty space
  199. $string = str_replace("\n", ' ', $string); // --- replace with space
  200. $string = str_replace("\t", ' ', $string); // --- replace with space
  201. // $string = str_replace("&nbsp;", ' ', $string); // --- replace with space
  202. // $string = str_replace("&#039;", '\'', $string); // --- replace with space
  203. // ----- remove multiple spaces -----
  204. $string = trim(preg_replace('/ {2,}/', ' ', $string));
  205. // ----- remove html entities
  206. preg_match_all('/&[^;]+;/', $string, $entities);
  207. foreach ($entities[0] as $entity) {
  208. $string = str_replace($entity, mb_convert_encoding($entity, 'UTF-8', 'HTML-ENTITIES'), $string);
  209. }
  210. return $string;
  211. }
  212. /**
  213. * Implements hook_block_info().
  214. */
  215. function materio_search_api_block_info() {
  216. // This example comes from node.module.
  217. $blocks['materio_search_api_search'] = array(
  218. 'info' => t('Materio search api search'),
  219. 'cache' => DRUPAL_NO_CACHE
  220. );
  221. $blocks['materio_search_api_viewmode'] = array(
  222. 'info' => t('Materio search api view mode selection'),
  223. 'cache' => DRUPAL_NO_CACHE
  224. );
  225. // $blocks['materio_search_api_filters'] = array(
  226. // 'info' => t('Materio search api filters'),
  227. // 'cache' => DRUPAL_NO_CACHE
  228. // );
  229. return $blocks;
  230. }
  231. /**
  232. * Implements hook_block_view().
  233. */
  234. function materio_search_api_block_view($delta = '') {
  235. // This example comes from node.module. Note that you can also return a
  236. // renderable array rather than rendered HTML for 'content'.
  237. $block = array();
  238. switch ($delta) {
  239. case 'materio_search_api_search':
  240. if (user_access('use materio search api') || user_access('use materio search api for breves')) {
  241. $block['subject'] = t('Search');
  242. $block['content'] = theme('materio_search_api_search_block', array());
  243. }
  244. break;
  245. case 'materio_search_api_viewmode':
  246. if (user_access('use materio search api viewmode selection')) {
  247. $block['subject'] = t('View mode');
  248. $block['content'] = theme('materio_search_api_select_viewmode_block', array());
  249. }
  250. break;
  251. // case 'materio_search_api_filters':
  252. // if (user_access('use materio search api filters')) {
  253. // $block['subject'] = t('Filters');
  254. // $block['content'] = theme('materio_search_api_filters_block', array());
  255. // }
  256. // break;
  257. }
  258. return $block;
  259. }
  260. /**
  261. * Implements hook_entity_info_alter().
  262. */
  263. function materio_search_api_entity_info_alter(&$entity_info) {
  264. $entity_info['node']['view modes']['cardsmall'] = array(
  265. 'label' => t('Small cards'),
  266. 'custom settings' => TRUE,
  267. );
  268. $entity_info['node']['view modes']['cardmedium'] = array(
  269. 'label' => t('Medium cards'),
  270. 'custom settings' => TRUE,
  271. );
  272. $entity_info['node']['view modes']['cardbig'] = array(
  273. 'label' => t('Big cards'),
  274. 'custom settings' => TRUE,
  275. );
  276. $entity_info['node']['view modes']['cardfull'] = array(
  277. 'label' => t('Full cards'),
  278. 'custom settings' => TRUE,
  279. );
  280. }
  281. /**
  282. * Implements hook_node_view().
  283. */
  284. function materio_search_api_node_view($node, $view_mode, $langcode) {
  285. if (in_array($view_mode, array('cardsmall','cardmedium', 'cardbig', 'cardfull'))) {
  286. # PRINT 7.1
  287. print_node_view($node, 'full');
  288. print_pdf_node_view($node, 'full');
  289. # PRINT 7.2-beta
  290. //print_ui_node_view($node, 'full');
  291. // dsm($node, 'node');
  292. }
  293. }
  294. /**
  295. * materiobase_search_form()
  296. */
  297. function materio_search_api_search_form($form, &$form_state){
  298. // dsm($form_state, 'form_state');
  299. // dsm($form, 'form');
  300. global $user;
  301. $form = array();
  302. $args = arg();
  303. $path = array_shift($args);
  304. $keys = implode('/', $args);
  305. $form['searchfield'] = array(
  306. '#type' => 'textfield',
  307. '#default_value' => $path == 'explore' ? $keys : "", // TODO: set the search page path global or a variable in settings
  308. // '#value' => $keys,
  309. '#autocomplete_path' => 'materiosearchapi/autocomplete/searchapi',
  310. //'#autocomplete_path' => 'materiosearchapi/autocomplete/dbselect',
  311. '#size' => 30,
  312. '#maxlength' => 1024,
  313. );
  314. if(user_access('use materio search api filters')){
  315. $index = search_api_index_load(variable_get('mainsearchindex', -1));
  316. $indexed_bundles = $index->options['data_alter_callbacks']['search_api_alter_bundle_filter']['settings']['bundles'];
  317. foreach ($indexed_bundles as $bundle) {
  318. $bundles_options[$bundle] = $bundle;
  319. $default_bundles[] = $bundle;
  320. }
  321. $user_bundles_filter = isset($user->data['materiosearchapi_bundlesfilter']) ? $user->data['materiosearchapi_bundlesfilter'] : $default_bundles;
  322. $form['bundles_filter'] = array(
  323. '#type'=>'checkboxes',
  324. '#options' => $bundles_options,
  325. '#default_value' => $user_bundles_filter,
  326. // '#attributes' => array('class'=>array('btn-group')),
  327. );
  328. }
  329. $form['create'] = array(
  330. '#type' => 'image_button',
  331. '#src' => drupal_get_path('module', 'materio_search_api') . '/images/search.png',
  332. '#value' => t('Search'),
  333. );
  334. return $form;
  335. }
  336. function materio_search_api_search_form_validate($form, &$form_state){
  337. // dsm($form, '$form');
  338. // dsm($form_state, '$form_state');
  339. // dsm(strlen($form_state['values']['searchfield']));
  340. if (strlen(trim($form_state['values']['searchfield'])) <= 1) {
  341. form_set_error('searchfield', 'Please enter at least 2 characters keyword.');
  342. }
  343. }
  344. function materio_search_api_search_form_submit($form, &$form_state){
  345. // dsm($form_state, 'form_state');
  346. global $user;
  347. if(user_access('use materio search api filters')){
  348. foreach($form_state['values']['bundles_filter'] as $bundle => $value)
  349. if($value)
  350. $bundles[] = $bundle;
  351. # if no filter checked we checked them all by default
  352. if(!isset($bundles))
  353. foreach($form_state['values']['bundles_filter'] as $bundle => $value)
  354. $bundles[] = $bundle;
  355. }else{
  356. # if user have no access to filters
  357. $index = search_api_index_load(variable_get('mainsearchindex', -1));
  358. $indexed_bundles = $index->options['data_alter_callbacks']['search_api_alter_bundle_filter']['settings']['bundles'];
  359. foreach ($indexed_bundles as $bundle) {
  360. $bundles[] = $bundle;
  361. }
  362. }
  363. user_save($user, array("data"=>array('materiosearchapi_bundlesfilter' => $bundles)));
  364. $form_state['redirect'] = 'explore/'.$form_state['values']['searchfield'];
  365. }
  366. /**
  367. * viewmode
  368. */
  369. function _materio_search_api_change_viewmode($vm){
  370. // dsm($vm, '_materio_search_api_change_viewmode');
  371. global $user;
  372. // dsm($user, 'user');
  373. $entity_infos = entity_get_info();
  374. // dsm($entity_infos, 'entity_infos');
  375. if (in_array($vm, variable_get('availableviewmodes', array()))) {
  376. user_save($user, array("data"=>array('materiosearchapi_viewmode' => $vm)));
  377. $rep = array('statut'=>'saved');
  378. }else{
  379. $rep = array('statut'=>'viewmode not allowed');
  380. }
  381. return $rep;
  382. }
  383. /**
  384. * - - - - - - - - - - - - THEME - - - - - - - - - - - -
  385. */
  386. /**
  387. * Implements hook_theme().
  388. */
  389. function materio_search_api_theme($existing, $type, $theme, $path) {
  390. return array(
  391. 'materio_search_api_search_block' => array(
  392. 'arguments' => array(),
  393. 'template' => 'materio-search-api-search-block',
  394. 'path' => drupal_get_path('module', 'materio_search_api').'/templates',
  395. ),
  396. 'materio_search_api_select_viewmode_block' => array(
  397. 'arguments' => array(),
  398. 'template' => 'materio-search-api-select-viewmode-block',
  399. 'path' => drupal_get_path('module', 'materio_search_api').'/templates',
  400. ),
  401. // 'materio_search_api_filters_block' => array(
  402. // 'arguments' => array(),
  403. // 'template' => 'materio-search-api-filters-block',
  404. // 'path' => drupal_get_path('module', 'materio_search_api').'/templates',
  405. // ),
  406. 'materio_search_api_results' => array(
  407. 'arguments' => array(),
  408. 'template' => 'materio-search-api-results',
  409. 'path' => drupal_get_path('module', 'materio_search_api').'/templates',
  410. 'variables' => array(
  411. 'index' => NULL,
  412. 'results' => array('result count' => 0),
  413. 'items' => array(),
  414. 'view_mode' => 'teaser',
  415. 'keys' => '',
  416. // 'page_machine_name' => NULL,
  417. 'spellcheck' => NULL,
  418. 'pager' => NULL,
  419. ),
  420. ),
  421. // 'materio_search_api_performance' => array(
  422. // 'render element' => 'element',
  423. // ),
  424. 'materio_search_api_actuality' => array(
  425. 'template' => 'materio-search-api-actuality',
  426. 'path' => drupal_get_path('module', 'materio_search_api').'/templates',
  427. 'arguments' => array(
  428. 'items' => array(),
  429. 'view_mode' => "teaser",
  430. 'pager' => NULL,
  431. 'count' => 0,
  432. )
  433. )
  434. );
  435. }
  436. /**
  437. * Implements theme for rendering search-performance
  438. */
  439. // function theme_materio_search_api_performance($variables) {
  440. // $element = array_shift($variables);
  441. // return $element['#markup'];
  442. // }
  443. /**
  444. * template_preprocess_materiobase_search_block();
  445. */
  446. function template_preprocess_materio_search_api_search_block(&$vars){
  447. // dsm($vars, '$vars');
  448. $vars['searchform'] = drupal_get_form("materio_search_api_search_form");
  449. }
  450. function template_preprocess_materio_search_api_select_viewmode_block(&$vars){
  451. global $user;
  452. $active = isset($user->data['materiosearchapi_viewmode']) ? $user->data['materiosearchapi_viewmode'] : variable_get('defaultviewmode', 'full');
  453. $availableviewmodes = variable_get('availableviewmodes', -1);
  454. // dsm($availableviewmodes);
  455. $entity_infos = entity_get_info();
  456. // dsm($entity_infos, 'entity_infos');
  457. $content = '<div class="btn-group btn-group-vertical">';
  458. foreach ($entity_infos['node']['view modes'] as $viewmode => $value) {
  459. if(in_array($viewmode, $availableviewmodes)){
  460. $link = l(
  461. '<i class="icon-materio-viewmode-'.$viewmode.($active == $viewmode ? " active" : '').'"></i><span class="inner">'.$value['label'].'</span>',
  462. 'materiosearchapi/viewmode/change/'.$viewmode,
  463. array(
  464. 'query' => drupal_get_destination(),
  465. 'html' => true,
  466. 'attributes' => array(
  467. 'class' => array(
  468. 'viewmode-link',
  469. 'viewmode-'.$viewmode,
  470. $active == $viewmode ? " active" : ''
  471. ),
  472. 'rel' => $viewmode
  473. )
  474. )
  475. );
  476. $content .= $link;
  477. }
  478. }
  479. $content .= '</div>';
  480. $vars['content'] = $content;
  481. }
  482. // function template_preprocess_materio_search_api_filters_block(&$vars){
  483. // $index_machine_name = variable_get('mainsearchindex', -1);
  484. // $index = search_api_index_load($index_machine_name);
  485. // dsm($index, 'index');
  486. // // $entity_infos = entity_get_info($index->item_type);
  487. // // dsm($entity_infos, 'entity_infos');
  488. // $indexed_bundles = $index->options['data_alter_callbacks']['search_api_alter_bundle_filter']['settings']['bundles'];
  489. // dsm($indexed_bundles, 'indexed_bundles');
  490. // $vars['content'] = drupal_get_form('materio_search_api_filters_form', $indexed_bundles);
  491. // }
  492. // function materio_search_api_filters_form($form, $form_state, $bundles){
  493. // $form = array();
  494. // dsm($bundles, 'bundles');
  495. // foreach ($bundles as $bundle) {
  496. // $form[$bundle . '_filter'] = array(
  497. // '#type'=>'checkbox',
  498. // '#default_value' => -1,
  499. // '#title' => $bundle,
  500. // );
  501. // }
  502. // return $form;
  503. // }
  504. /**
  505. * Function for preprocessing the variables for the search_api_page_results
  506. * template.
  507. *
  508. * @param array $variables
  509. * An associative array containing:
  510. * - $index: The index this search was executed on.
  511. * - $results: An array of search results, as returned by
  512. * SearchApiQueryInterface::execute().
  513. * - $keys: The keywords of the executed search.
  514. *
  515. * @see materio-search-api-results.tpl.php
  516. */
  517. function template_preprocess_materio_search_api_results(array &$variables) {
  518. // dsm($variables, '$variables');
  519. $results = $variables['results'];
  520. $keys = $variables['keys'];
  521. // $variables['items'] = $variables['index']->loadItems(array_keys($variables['results']['results']));
  522. $variables['result_count'] = $results['result count'];
  523. $variables['sec'] = round($results['performance']['complete'], 3);
  524. if(isset($results['breves count'])){
  525. $variables['search_performance'] = format_plural(
  526. $results['breves count'],
  527. 'The search found 1 news ',
  528. 'The search found @count news '
  529. );
  530. $variables['search_performance'] .= format_plural(
  531. $variables['result_count'] - $results['breves count'],
  532. 'with 1 associated matter.',
  533. 'with @count associated matters.'
  534. );
  535. $variables['search_performance'] .= format_plural(
  536. $results['could results']['result count'],
  537. ' You could find 1 result with a ',
  538. ' You could find @count results with a '
  539. );
  540. $variables['search_performance'] .= l(t('full access to materiO\'.'), 'node/11187');
  541. }else{
  542. $variables['search_performance'] = format_plural(
  543. // $results['result count'],
  544. $variables['result_count'],
  545. 'The search found 1 result.',
  546. 'The search found @count results.'
  547. );
  548. }
  549. //dsm($variables, 'variables');
  550. }
  551. function template_preprocess_materio_search_api_actuality(&$vars){
  552. // dsm($vars, 'template_preprocess_materio_search_api_actuality | vars');
  553. // $vars['actualities_infos'] = t('Actualities by materiO\'');
  554. $vars['actualities_infos'] = t('');
  555. }
  556. /**
  557. * - - - - - - - - - - - - SEARCH API PAGE - - - - - - - - - - - -
  558. */
  559. /**
  560. * Implements hook_block_view_alter().
  561. */
  562. function materio_search_api_block_view_alter(&$data, $block) {
  563. // this alter prepopulate the search form provide by search_api_page
  564. if ($block->module == 'search_api_page') {
  565. $page = search_api_page_load($block->delta);
  566. $item = menu_get_item();
  567. if (isset($page->path) && $page->path == $item['path']) {
  568. $keys = arg(count(arg(NULL, $page->path)));
  569. if ($keys) {
  570. $data['content']['keys_' . $page->id]['#default_value'] = $keys;
  571. $data['content']['keys_' . $page->id]['#value'] = $keys;
  572. }
  573. }
  574. }
  575. }