How to use drupal behaviors on drupal 8?

What is drupal behaviors ?
Drupal behaviors allow to execute javascpts in particular context and / or pass data from drupal to client side java script.

* Implements hook_js_settings_alter(). 
* @inheritdoc 

function custom_module_js_settings_alter(array &$settings, 
\Drupal\Core\Asset\AttachedAssetsInterface $assets) {

 $settings['custom_module']['text'] = "The text";

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.