public function GoogleCSESearch::buildConfigurationForm in Google Custom Search Engine 8.3
Same name and namespace in other branches
- 8.2 src/Plugin/Search/GoogleCSESearch.php \Drupal\google_cse\Plugin\Search\GoogleCSESearch::buildConfigurationForm()
Form constructor.
Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and #array_parents, see \Drupal\Core\Render\Element\FormElement.
Parameters
array $form: An associative array containing the initial structure of the plugin form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().
Return value
array The form structure.
Overrides PluginFormInterface::buildConfigurationForm
File
- src/
Plugin/ Search/ GoogleCSESearch.php, line 214
Class
- GoogleCSESearch
- Handles searching for node entities using the Search module index.
Namespace
Drupal\google_cse\Plugin\SearchCode
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['google_cse'] = [
'#title' => $this
->t('Google CSE'),
'#type' => 'details',
'#open' => TRUE,
];
$form['google_cse']['cx'] = [
'#title' => $this
->t('Google Custom Search Engine ID'),
'#type' => 'textfield',
'#default_value' => $this->configuration['cx'] ?? '',
'#description' => $this
->t('Enter your @google (click on control panel).', [
'@google' => Link::fromTextAndUrl('Google CSE unique ID', Url::fromUri('http://www.google.com/cse/manage/all'))
->toString(),
]),
'#required' => TRUE,
];
$form['google_cse']['results_tab'] = [
'#title' => $this
->t('Search results tab name'),
'#type' => 'textfield',
'#maxlength' => 50,
'#size' => 60,
'#description' => $this
->t('Enter a custom name of the tab where search results are displayed (defaults to %google).', [
'%google' => $this
->t('Google'),
]),
'#default_value' => $this->configuration['results_tab'] ?? '',
];
$form['google_cse']['results_width'] = [
'#title' => $this
->t('Search results frame width'),
'#type' => 'textfield',
'#maxlength' => 4,
'#size' => 6,
'#description' => $this
->t('Enter the desired width, in pixels, of the search frame.'),
'#default_value' => $this->configuration['results_width'] ?? '',
];
$form['google_cse']['cof_here'] = [
'#title' => $this
->t('Ad format on this site'),
'#type' => 'radios',
'#default_value' => $this->configuration['cof_here'] ?? '',
'#options' => [
'FORID:9' => $this
->t('Right'),
'FORID:10' => $this
->t('Top and right'),
'FORID:11' => $this
->t('Top and bottom'),
],
'#description' => $this
->t('Ads on the right increase the width of the iframe. Non-profit organizations can disable ads in the Google CSE control panel.'),
];
$form['google_cse']['cof_google'] = [
'#title' => $this
->t('Ad format on Google'),
'#type' => 'radios',
'#default_value' => $this->configuration['cof_google'] ?? '',
'#options' => [
'FORID:0' => $this
->t('Right'),
'FORID:1' => $this
->t('Top and bottom'),
],
'#description' => $this
->t('AdSense ads are also displayed when the CSE links or redirects to Google.'),
];
$form['google_cse']['results_prefix'] = [
'#title' => $this
->t('Search results prefix text'),
'#type' => 'textarea',
'#cols' => 50,
'#rows' => 4,
'#description' => $this
->t('Enter text to appear on the search page before the search form.'),
'#default_value' => $this->configuration['results_prefix'] ?? '',
];
$form['google_cse']['results_suffix'] = [
'#title' => $this
->t('Search results suffix text'),
'#type' => 'textarea',
'#cols' => 50,
'#rows' => 4,
'#description' => $this
->t('Enter text to appear on the search page after the search form and results.'),
'#default_value' => $this->configuration['results_suffix'] ?? '',
];
$form['google_cse']['results_searchbox_width'] = [
'#title' => $this
->t('Google CSE block searchbox width'),
'#type' => 'textfield',
'#maxlength' => 4,
'#size' => 6,
'#description' => $this
->t('Enter the desired width, in characters, of the searchbox on the Google CSE block.'),
'#default_value' => $this->configuration['results_searchbox_width'] ?? '',
];
$form['google_cse']['results_display'] = [
'#title' => $this
->t('Display search results'),
'#type' => 'radios',
'#default_value' => $this->configuration['results_display'] ?? 'here',
'#options' => [
'here' => $this
->t('On this site (requires JavaScript)'),
'google' => $this
->t('On Google'),
],
'#description' => $this
->t('Search results for the Google CSE block can be displayed on this site, using JavaScript, or on Google, which does not require JavaScript.'),
'#required' => TRUE,
];
$cx = isset($this->configuration['cx']) ? (string) $this->configuration['cx'] : '';
$form['google_cse']['custom_results_display'] = [
'#title' => $this
->t('Layout of Search Engine'),
'#type' => 'radios',
'#default_value' => $this->configuration['custom_results_display'] ?? 'results-only',
'#options' => [
'overlay' => $this
->t('Overlay'),
'two-page' => $this
->t('Two page'),
'full-width' => $this
->t('Full width'),
'two-column' => $this
->t('Two column'),
'compact' => $this
->t('Compact'),
'results-only' => $this
->t('Results only'),
'google-hosted' => $this
->t('Google hosted'),
],
'#description' => $this
->t('Set the search engine layout, as found in the Layout tab of @url.', [
'@url' => Link::fromTextAndUrl('Custom Search settings', Url::fromUri('https://www.google.com/cse/lookandfeel/layout?cx=' . $cx))
->toString(),
]),
'#required' => TRUE,
];
$form['google_cse']['results_display_images'] = [
'#title' => $this
->t('Display thumbnail images in the search results'),
'#type' => 'checkbox',
'#description' => $this
->t('If set, search result snippets will contain a thumbnail image'),
'#default_value' => $this->configuration['results_display_images'] ?? '',
];
$form['google_cse']['sitesearch'] = [
'#title' => $this
->t('SiteSearch settings'),
'#type' => 'details',
'#open' => FALSE,
];
$form['google_cse']['sitesearch']['sitesearch'] = [
'#title' => $this
->t('SiteSearch domain'),
'#type' => 'textarea',
'#cols' => 50,
'#rows' => 4,
'#description' => $this
->t('If set, users will be presented with the option of searching only on the domain(s) specified rather than using the CSE. Enter one domain or URL path followed by a description (e.g. %example) on each line.', [
'%example' => 'example.com/user Search users',
]),
'#default_value' => $this->configuration['sitesearch'] ?? '',
];
$form['google_cse']['sitesearch']['sitesearch_form'] = [
'#title' => $this
->t('SiteSearch form element'),
'#type' => 'radios',
'#options' => [
'radios' => $this
->t('Radio buttons'),
'select' => $this
->t('Select'),
],
'#description' => $this
->t('Select the type of form element used to present the SiteSearch option(s).'),
'#default_value' => $this->configuration['sitesearch_form'] ?? '',
];
$form['google_cse']['sitesearch']['sitesearch_option'] = [
'#title' => $this
->t('CSE search option label'),
'#type' => 'textfield',
'#maxlength' => 50,
'#size' => 60,
'#description' => $this
->t('Customize the label for CSE search if SiteSearch is enabled (defaults to %search-web).', [
'%search-web' => 'Search the web',
]),
'#default_value' => $this->configuration['sitesearch_option'] ?? '',
];
$form['google_cse']['sitesearch']['sitesearch_default'] = [
'#title' => $this
->t('Default to using the SiteSearch domain'),
'#type' => 'checkbox',
'#description' => $this
->t('If set, searches will default to using the first listed SiteSearch domain rather than the CSE.'),
'#default_value' => $this->configuration['sitesearch_default'] ?? '',
];
$form['google_cse']['advanced'] = [
'#title' => $this
->t('Advanced settings'),
'#type' => 'details',
'#open' => FALSE,
];
$form['google_cse']['advanced']['domain'] = [
'#title' => $this
->t('Search domain'),
'#type' => 'textfield',
'#maxlength' => 64,
'#description' => $this
->t('Enter the Google domain to use for search results, e.g. %google.', [
'%google' => 'www.google.com',
]),
'#default_value' => $this->configuration['domain'] ?? '',
];
$form['google_cse']['advanced']['limit_domain'] = [
'#title' => $this
->t('Limit results to this domain'),
'#type' => 'textfield',
'#maxlength' => 64,
'#description' => $this
->t('Enter the domain to limit results on (only display results for this domain) %google.', [
'%google' => 'www.google.com',
]),
'#default_value' => $this->configuration['limit_domain'] ?? '',
];
$form['google_cse']['advanced']['cr'] = [
'#title' => $this
->t('Country restriction'),
'#type' => 'textfield',
'#default_value' => $this->configuration['cr'] ?? '',
'#description' => $this
->t('Enter a 9-letter country code, e.g. %countryNZ, and optional boolean operators, to restrict search results to documents (not) originating in particular countries. See the @crparameter.', [
'%countryNZ' => 'countryNZ',
'@crparameter' => Link::fromTextAndUrl($this
->t('%cr parameter', [
'%cr' => 'cr',
]), Url::fromUri('https://developers.google.com/custom-search/docs/xml_results#crsp'))
->toString(),
]),
];
$form['google_cse']['advanced']['gl'] = [
'#title' => $this
->t('Country boost'),
'#type' => 'textfield',
'#default_value' => $this->configuration['gl'] ?? '',
'#description' => $this
->t('Enter a 2-letter country code, e.g. %uk, to boost documents written in a particular country. See the @glparameter.', [
'%uk' => 'uk',
'@glparameter' => Link::fromTextAndUrl($this
->t('%gl parameter', [
'%gl' => 'gl',
]), Url::fromUri('https://developers.google.com/custom-search/docs/xml_results#glsp'))
->toString(),
]),
];
$form['google_cse']['advanced']['hl'] = [
'#title' => $this
->t('Interface language'),
'#type' => 'textfield',
'#default_value' => $this->configuration['hl'] ?? '',
'#description' => $this
->t('Enter a supported 2- or 5-character language code, e.g. %fr, to set the language of the user interface. See the @hlparameter.', [
'%fr' => 'fr',
'@hlparameter' => Link::fromTextAndUrl($this
->t('%hl parameter', [
'%hl' => 'hl',
]), Url::fromUri('https://developers.google.com/custom-search/docs/xml_results#hlsp'))
->toString(),
]),
];
$form['google_cse']['advanced']['locale_hl'] = [
'#title' => $this
->t('Set interface language dynamically'),
'#type' => 'checkbox',
'#default_value' => $this->configuration['locale_hl'] ?? '',
'#description' => $this
->t('The language restriction can be set dynamically if the locale module is enabled. Note the locale language code must match one of the @google.', [
'@google' => Link::fromTextAndUrl('supported language codes', Url::fromUri('https://developers.google.com/custom-search/docs/xml_results#interfaceLanguages'))
->toString(),
]),
];
$form['google_cse']['advanced']['ie'] = [
'#title' => $this
->t('Input encoding'),
'#type' => 'textfield',
'#default_value' => $this->configuration['ie'] ?? '',
'#description' => $this
->t('The default %utf8 is recommended. See the @ieparameter.', [
'%utf8' => 'utf-8',
'@ieparameter' => Link::fromTextAndUrl($this
->t('%ie parameter', [
'%ie' => 'ie',
]), Url::fromUri('https://developers.google.com/custom-search/docs/xml_results#iesp'))
->toString(),
]),
];
$form['google_cse']['advanced']['lr'] = [
'#title' => $this
->t('Language restriction'),
'#type' => 'textfield',
'#default_value' => $this->configuration['lr'] ?? '',
'#description' => $this
->t('Enter a supported 7- or 10-character language code, e.g. %lang_en, and optional boolean operators, to restrict search results to documents (not) written in particular languages. See the @lrparameter.', [
'%langen' => 'lang_en',
'@lrparameter' => Link::fromTextAndUrl($this
->t('%lr parameter', [
'%lr' => 'lr',
]), Url::fromUri('https://developers.google.com/custom-search/docs/xml_results#lrsp'))
->toString(),
]),
];
$form['google_cse']['advanced']['locale_lr'] = [
'#title' => $this
->t('Set language restriction dynamically'),
'#type' => 'checkbox',
'#default_value' => $this->configuration['locale_lr'] ?? '',
'#description' => $this
->t('The language restriction can be set dynamically if the locale module is enabled. Note the locale language code must match one of the @supported.', [
'@supported' => Link::fromTextAndUrl('supported language codes', Url::fromUri('https://developers.google.com/custom-search/docs/xml_results#languageCollections'))
->toString(),
]),
];
$form['google_cse']['advanced']['oe'] = [
'#title' => $this
->t('Output encoding'),
'#type' => 'textfield',
'#default_value' => $this->configuration['oe'] ?? '',
'#description' => $this
->t('The default %utf is recommended. See the @oeparameter.', [
'%utf' => 'utf-8',
'@oeparameter' => Link::fromTextAndUrl($this
->t('%oe parameter', [
'%oe' => 'oe',
]), Url::fromUri('https://developers.google.com/custom-search/docs/xml_results#oesp'))
->toString(),
]),
];
$form['google_cse']['advanced']['safe'] = [
'#title' => $this
->t('SafeSearch filter'),
'#type' => 'select',
'#options' => [
'' => '',
'off' => $this
->t('Off'),
'medium' => $this
->t('Medium'),
'high' => $this
->t('High'),
],
'#default_value' => $this->configuration['safe'] ?? '',
'#description' => $this
->t('SafeSearch filters search results for adult content. See the @safeparameter.', [
'@safeparameter' => Link::fromTextAndUrl('safe parameter', Url::fromUri('https://developers.google.com/custom-search/docs/xml_results#safesp'))
->toString(),
]),
];
$form['google_cse']['advanced']['custom_css'] = [
'#title' => t('Stylesheet Override'),
'#type' => 'textfield',
'#default_value' => $this->configuration['custom_css'] ?? '',
'#description' => $this
->t('Set a custom stylesheet to override or add any styles not allowed in the CSE settings (such as "background-color: none;"). Include <span style="color:red; font-weight:bold;">!important</span> for overrides.<br/>Example: %replace', [
'%replace' => '//replacewithrealsite.com/sites/all/modules/google_cse/default.css',
]),
];
return $form;
}