diff --git a/mmoda.module b/mmoda.module index 9bb842e..1dcfca8 100644 --- a/mmoda.module +++ b/mmoda.module @@ -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)); @@ -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; } /** @@ -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(); @@ -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( @@ -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; }