public function ColorizedGmapBlock::checkApiKey in Colorized google maps block 8
Helper function check if google api keys is set.
2 calls to ColorizedGmapBlock::checkApiKey()
- ColorizedGmapBlock::blockForm in src/
Plugin/ Block/ ColorizedGmapBlock.php - ColorizedGmapBlock::build in src/
Plugin/ Block/ ColorizedGmapBlock.php - Builds and returns the renderable array for this block plugin.
File
- src/
Plugin/ Block/ ColorizedGmapBlock.php, line 214
Class
- ColorizedGmapBlock
- Provides a 'Example: configurable text string' block.
Namespace
Drupal\colorized_gmap\Plugin\BlockCode
public function checkApiKey() {
$config = $this->configFactory
->get('colorized_gmap.settings');
$api_key = $config
->get('colorized_gmap_api_key');
if (empty($api_key)) {
$url = Url::fromUri('http://googlegeodevelopers.blogspot.ru/2016/06/building-for-scale-updates-to-google.html');
$url
->setOptions([
'external' => TRUE,
'attributes' => [
'target' => '_blank',
],
]);
$info_link = Link::fromTextAndUrl($this
->t('api key'), $url)
->toString();
$url = Url::fromUri('https://developers.google.com/maps/documentation/javascript/get-api-key');
$url
->setOptions([
'external' => TRUE,
'attributes' => [
'target' => '_blank',
],
]);
$get_key_link = Link::fromTextAndUrl($this
->t('this'), $url)
->toString();
$url = Url::fromRoute('colorized_gmap.admin_settings');
$settings_link = Link::fromTextAndUrl($this
->t('module settings page'), $url)
->toString();
$missing_api_key_message = $this
->t('Google maps are no longer working without @info. Please visit @get-key page to get API key and follow further instructions. After that, please enter your api key on @settings-page.', [
'@info' => $info_link,
'@get-key' => $get_key_link,
'@settings-page' => $settings_link,
]);
$this
->messenger()
->addWarning($missing_api_key_message);
}
}