birthdaywish_firework-1.0.0/birthday_wish_firework.module
birthday_wish_firework.module
<?php
use \Drupal\user\Entity\User;
/**
* Implements hook_page_attachments().
*/
function birthday_wish_firework_page_attachments(array &$attachments) {
// Load the configuration data for 'birthday_wish_firework.settings'.
$myConfigPageData = \Drupal::configFactory()->getEditable('birthday_wish_firework.settings');
$enFirework = $myConfigPageData->get('enable_fireworks');
// Load the currently logged-in user.
$current_user = \Drupal::currentUser();
$uid = $current_user->id();
$user = User::load($uid);
// Check if the user entity has the "field_birthdate" field.
if($user->hasField('field_birthdate')){
$bdate = $user->get('field_birthdate')->value;
$attachments['#attached']['drupalSettings']['bdate'] = $bdate;
}
// Attach the 'fireworksjs' library and set drupalSettings.
$attachments['#attached']['drupalSettings']['firework'] = $enFirework;
$attachments['#attached']['library'][] = 'birthday_wish_firework/fireworksjs';
}