-
-
Save liberatr/856be5c7e37badb366f02ba612ebc1dc to your computer and use it in GitHub Desktop.
Drupal 8 - Example of adding dynamic js libraries which require locale
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Implements hook_library_info_build(). | |
* | |
* @return array | |
*/ | |
function mymodule_library_info_build() { | |
$libraries = []; | |
$api_key = \Drupal::config('mymodule.api_key'); | |
$libraries['mymodule.map'] = [ | |
'js' => [ | |
'https://www.googleapis.com/geolocation/v1/geolocate?key=' . $api_key => [], | |
], | |
]; | |
return $libraries; | |
} | |
/** | |
* Implements hook_page_attachments(). | |
*/ | |
function mymodule_page_attachments(array &$page) { | |
$page['#attached']['library'][] = 'mymodule/map'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment