public static function GoogleSearch::createRenderArray in Freelinking 4.0.x
Same name and namespace in other branches
- 8.3 src/Plugin/freelinking/GoogleSearch.php \Drupal\freelinking\Plugin\freelinking\GoogleSearch::createRenderArray()
Create a google search link.
Parameters
string $searchString: The search string to use, which should already have spaces replaced with plus signs.
string $text: The text to display for the link.
\Drupal\Core\Language\LanguageInterface|null $language: The language code.
\Drupal\Core\StringTranslation\TranslatableMarkup $tip: The tooltip to use.
Return value
array A valid link render array.
2 calls to GoogleSearch::createRenderArray()
- GoogleSearch::buildLink in src/
Plugin/ freelinking/ GoogleSearch.php - Build a link with the plugin.
- Search::buildLink in src/
Plugin/ freelinking/ Search.php - Build a link with the plugin.
File
- src/
Plugin/ freelinking/ GoogleSearch.php, line 62
Class
- GoogleSearch
- Freelinking google search plugin.
Namespace
Drupal\freelinking\Plugin\freelinkingCode
public static function createRenderArray($searchString, $text, $language, TranslatableMarkup $tip) {
// @todo Fix so that language is typed.
$lang = NULL === $language || LanguageInterface::LANGCODE_DEFAULT === $language
->getId() ? 'en' : $language
->getId();
return [
'#type' => 'link',
'#title' => 'Google Search ' . $text,
'#url' => Url::fromUri('https://google.com/search', [
'absolute' => TRUE,
'query' => [
'q' => $searchString,
'hl' => $lang,
],
'language' => $language,
]),
'#attributes' => array(
'title' => $tip,
),
];
}