Skip to content

Commit

Permalink
Merge branch 'd10-main' of github.com:oda-hub/mmoda-frontend-module i…
Browse files Browse the repository at this point in the history
…nto d10-main
  • Loading branch information
burnout87 committed Sep 3, 2024
2 parents 518a9dd + 98a891a commit e9f9c08
Showing 1 changed file with 33 additions and 26 deletions.
59 changes: 33 additions & 26 deletions mmoda.module
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use Firebase\JWT\JWT;
use Firebase\JWT\Key;
use Drupal\Core\Logger\RfcLogLevel;

use Drupal\Core\Render\BubbleableMetadata;

function mmoda_node_update($node)
{
error_log("updated node\n" . print_r($node->id(), true));
Expand Down Expand Up @@ -49,15 +51,16 @@ function mmoda_theme($existing, $type, $theme, $path)
/**
* Implements hook_token_info().
*/
function mmoda_token_info() {
$types['site-logo-url'] = [
'name' => t('Site logo'),
'description' => t('Current theme site logo.'),
];
return [
'types' => $types,
'tokens' => ['site' => $tokens],

function mmoda_token_info() : array {
$info = [];

$info['tokens']['site']['logo-url'] = [
'name' => 'Site logo',
'description' => t('Current theme site logo')
];

return $info;
}

/**
Expand All @@ -66,6 +69,28 @@ function mmoda_token_info() {
function mmoda_tokens($type, $tokens, array $data = array(), array $options = array()) {
$replacements = array();
$token_service = \Drupal::token();
if ($type == 'site') {
foreach ($tokens as $name => $original) {
switch ($name) {
case 'logo-url':
$theme = \Drupal::config('system.theme')->get('default');
$host = \Drupal::request()->getSchemeAndHttpHost();

$logo_url= $host.theme_get_setting('logo', $theme)['url'];
//$theme = \Drupal::theme()->getDefault();
//global $base_url;
//$logo_url= $base_url.'/'.$theme->getLogo();

$replacements[$original] = $logo_url;
error_log('Logo:'.$logo_url);
break;

default:
break;
}
}
}

if ($type === 'jwt') {
//global $user;
$user = \Drupal::currentUser();
Expand All @@ -78,16 +103,7 @@ function mmoda_tokens($type, $tokens, array $data = array(), array $options = ar
switch ($name) {
case 'jwt-link':
if (\Drupal::currentUser()->isAuthenticated()) {

// $jwt = jwt_link_url();
// $alg = variable_get('jwt_link_alg', 'HS256');
// $key = variable_get('jwt_link_key', '');
// $jwt_encoded_token_updated = $jwt['jwt_encoded_token'];
// $jwt_encoded_url_updated = $jwt['jwt_encoded_url'];
$jwt_service = \Drupal::service('jwt.transcoder');
// $key = \Drupal::config('jwt.settings')->get('key');
// $alg = \Drupal::config('jwt.settings')->get('algorithm');

$alg = variable_get('jwt_link_alg', 'HS256');
$key = variable_get('jwt_link_key', '');
$jwt_decoded_token = JWT::decode($jwt_encoded_token_updated, $key, array(
Expand Down Expand Up @@ -131,15 +147,6 @@ function mmoda_tokens($type, $tokens, array $data = array(), array $options = ar
}
}
}
foreach ($tokens as $name => $original) {
switch ($name) {
case 'site-logo-url':
$theme = \Drupal::theme()->getActiveTheme();
$replacements[$original] = $theme->getLogo();
error_log('Logo:'.$theme->getLogo());
break;
}
}

return $replacements;
}
Expand Down

0 comments on commit e9f9c08

Please sign in to comment.