/**
  * {@inheritdoc}
  */
 public function build()
 {
     $is_admin = \Drupal::service('router.admin_context')->isAdminRoute();
     if ($is_admin) {
         return [];
     }
     global $base_url;
     $output['#theme'] = "searchblox_frontend_view";
     $output['#var1'] = "vars_set_from_module_file";
     $output['#type'] = "markup";
     $output['#attributes'] = ['class' => ['searchblox-div']];
     // Prepare Vars For Setting them in Drupal.Settings
     $search_url = searchblox_location() ? searchblox_location() . '/searchblox/servlet/SearchServlet' : '';
     $auto_suggest_url = searchblox_location() ? searchblox_location() . '/searchblox/servlet/AutoSuggest' : '';
     $report_servlet_url = searchblox_location() ? searchblox_location() . '/searchblox/servlet/ReportServlet' : '';
     $full_plugin_url = searchblox_full_plugin_url();
     $collection_ids = array();
     $collection_ids = \Drupal::state()->get('searchblox_collection_ids') ? \Drupal::state()->get('searchblox_collection_ids') : '';
     $output['#attached']['drupalSettings']["searchblox"]["base_url"] = $base_url;
     $output['#attached']['drupalSettings']["searchblox"]["module_url"] = $base_url . "/modules/searchblox";
     $output['#attached']['drupalSettings']["searchblox"]["search_url"] = $search_url;
     $output['#attached']['drupalSettings']["searchblox"]["auto_suggest_url"] = $auto_suggest_url;
     $output['#attached']['drupalSettings']["searchblox"]["report_servlet_url"] = $report_servlet_url;
     $output['#attached']['drupalSettings']["searchblox"]["full_plugin_url"] = $full_plugin_url;
     $output['#attached']['drupalSettings']["searchblox"]["collection_ids"] = $collection_ids;
     // Attach Library
     $output['#attached']['library'][] = 'searchblox/searchblox-frontpage';
     $this->rendered_content = $output;
     return $output;
 }
 public function sbSettings()
 {
     if (!$this->searchblox_apikey || !searchblox_location()) {
         $response = new RedirectResponse(\Drupal::url('searchblox.step1'));
         $response->send();
     } elseif (!$this->searchblox_collection) {
         $response = new RedirectResponse(\Drupal::url('searchblox.step2'));
         $response->send();
     } else {
         $response = new RedirectResponse(\Drupal::url('searchblox.step3'));
         $response->send();
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $location = searchblox_location();
     $response = "";
     if (!$location) {
         $form_state->setErrorByName('error', t('<p> SearchBlox settings not configured yet. </p>'));
     } else {
         $url = $location . '/searchblox/servlet/SearchServlet?&query=""&xsl=json';
         $response = searchblox_curl_get_request($url);
     }
     $collections = array();
     if ($response) {
         $collections = $response->searchform->collections;
     }
     if (empty($collections)) {
         $form_state->setErrorByName('error', t('<p> You have created no collections yet. </p>'));
     }
     $header = array('id' => t('ID'), 'collection_name' => t('Collection Name'));
     $options = $collec_names = $default_value = array();
     // Collections already selected by user
     $collec_names = \Drupal::state()->get('searchblox_search_collection');
     foreach ($collections as $collection) {
         $options[$collection->{'@name'}] = array('id' => t(Html::escape($collection->{'@id'})), 'collection_name' => t(Html::escape($collection->{'@name'})));
         if ($collec_names) {
             // If the collection is the one already selected than mark it.
             if (in_array($collection->{'@name'}, $collec_names)) {
                 $default_value[$collection->{'@name'}] = true;
                 // Should have same key as options array
             }
         }
     }
     $form['header'] = array('#type' => 'item', '#markup' => '<div class="searchblox-logo" > 
    <h2 class="searchblox-h2">SearchBlox Search Module</h2> 
  </div>');
     $form['page_details'] = array('#type' => 'fieldset', '#title' => t('Mark the collections you want to show your search results from.'), '#description' => t('<p><strong>NOTE : If not marked, it will search from all of the available collections on your server.</strong></p>'));
     $form['searchblox_list_collection'] = array('#type' => 'tableselect', '#header' => $header, '#options' => $options, '#empty' => t('No Collections found'), '#default_value' => $default_value);
     $form['actions']['#type'] = 'actions';
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Save'), '#button_type' => 'primary');
     return $form;
 }