I've created a behaviours in JS but when I'm not connected as admin it show in the console this error:
Can't find variable: Drupal
When I write console.log(Drupal)
in the console explorer it show too the error.
How I can fix this error ?
Edit :
I've defined my library by this way :
myc_facebook:
version: 1.x
js:
js/script.js: {}
js/timeago.js: {}
dependencies:
- core/jquery
- core/drupalSettings
I integrate my library in a block by this way :
public function build() {
$config = $this->getConfiguration();
// Check if the conf
if (empty($config['token']) || empty($config['pagename']) || empty($config['pageurl']) || empty($config['limit']))
return array('err' => array('#markup' => t('You might configure this block.')));
$build = [];
// Create the wrapper to include facebook posts
$build['facebook']['timeline']['#markup'] = '<div id="myc-fb-posts" class="slider"><ul class="slides"></ul></div>';
// Push conf vars
foreach ($config as $key => $value) {
$build['#attached']['drupalSettings']['myc_fb'][$key] = $value;
}
// Includes libraries
$build['#attached']['library'][] = 'myc_facebook/myc_facebook';
return $build;
}