You are here

public function GoogleCSESearchBoxForm::buildForm in Google Custom Search Engine 8.3

Same name and namespace in other branches
  1. 8.2 src/Form/GoogleCSESearchBoxForm.php \Drupal\google_cse\Form\GoogleCSESearchBoxForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

src/Form/GoogleCSESearchBoxForm.php, line 67

Class

GoogleCSESearchBoxForm
Class GoogleCSESearchBoxForm.

Namespace

Drupal\google_cse\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('search.page.google_cse_search');
  if ($config
    ->get('configuration')['results_display'] == 'here') {
    $cof = $config
      ->get('configuration')['cof_here'];
  }
  else {
    $form['#action'] = $this->googleCSEServices
      ->getProtocol() . $config
      ->get('configuration')['domain'] . '/cse';
    $cof = $config
      ->get('configuration')['cof_google'];
  }
  $form['#method'] = 'get';
  $form['cx'] = [
    '#type' => 'hidden',
    '#value' => $config
      ->get('configuration')['cx'],
  ];
  $form['cof'] = [
    '#type' => 'hidden',
    '#value' => $cof,
  ];
  $form['keys'] = [
    '#type' => 'textfield',
    '#default_value' => $this->requestStack
      ->getCurrentRequest()->query
      ->has('query') ? $this->requestStack
      ->getCurrentRequest()->query
      ->get('query') : '',
  ];
  $form['sa'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Search'),
  ];
  foreach ($this->googleCSEServices
    ->advancedSettings() as $parameter => $setting) {
    $form[$parameter] = [
      '#type' => 'hidden',
      '#value' => $setting,
    ];
  }
  $form['keys']['#size'] = intval($config
    ->get('configuration')['results_searchbox_width']);
  $form['keys']['#title'] = $this
    ->t('Enter your keywords');
  $this->googleCSEServices
    ->siteSearchForm($form);
  return $form;
}