Skip to content

Commit

Permalink
set global twig variables using controller
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-jackson committed Jul 16, 2024
1 parent 3ee5ce9 commit 0dd3a9b
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 24 deletions.
2 changes: 1 addition & 1 deletion dockerbuild/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@
* the 'theme.controller' configuration option to a class that implements the
* \SimpleSAML\XHTML\TemplateControllerInterface interface to use it.
*/
//'theme.controller' => '',
'theme.controller' => '\SimpleSAML\Module\material\MaterialController',

/*
* Templating options
Expand Down
2 changes: 0 additions & 2 deletions modules/expirychecker/public/about2expire.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@
$globalConfig = Configuration::getInstance();

$t = new Template($globalConfig, 'expirychecker:about2expire');
$t->data['theme_color_scheme'] = $globalConfig->getOptionalString('theme.color-scheme', null);
$t->data['analytics_tracking_id'] = $globalConfig->getOptionalString('analytics.trackingId', '');
$t->data['form_target'] = Module::getModuleURL('expirychecker/about2expire.php');
$t->data['form_data'] = ['StateId' => $stateId];
$t->data['days_left'] = $state['daysLeft'];
Expand Down
2 changes: 0 additions & 2 deletions modules/expirychecker/public/expired.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@
$globalConfig = Configuration::getInstance();

$t = new Template($globalConfig, 'expirychecker:expired');
$t->data['theme_color_scheme'] = $globalConfig->getOptionalString('theme.color-scheme', null);
$t->data['analytics_tracking_id'] = $globalConfig->getOptionalString('analytics.trackingId', '');
$t->data['form_target'] = Module::getModuleURL('expirychecker/expired.php');
$t->data['form_data'] = ['StateId' => $stateId];
$t->send();
Expand Down
34 changes: 34 additions & 0 deletions modules/material/src/MaterialController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace SimpleSAML\Module\material;

use SimpleSAML\Configuration;
use SimpleSAML\XHTML\TemplateControllerInterface;
use Twig\Environment;

class MaterialController implements TemplateControllerInterface
{
/**
* Modify the twig environment after its initialization (e.g. add filters or extensions).
*
* @param \Twig\Environment $twig The current twig environment.
* @return void
*/
public function setUpTwig(Environment &$twig): void
{
}

/**
* Add, delete or modify the data passed to the template.
* This method will be called right before displaying the template.
*
* @param array $data The current data used by the template.
* @return void
*/
public function display(array &$data): void
{
$globalConfig = Configuration::getInstance();
$data['theme_color_scheme'] = $globalConfig->getOptionalString('theme.color-scheme', null);
$data['analytics_tracking_id'] = $globalConfig->getOptionalString('analytics.trackingId', '');
}
}
2 changes: 1 addition & 1 deletion modules/material/themes/material/default/header.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<base href="{{ baseurlpath }}/module.php/material/">

{% if analytics_tracking_id is defined and analytics_tracking_id is not empty %}
{% if analytics_tracking_id is not empty %}
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{ analytics_tracking_id }}"></script>
<script>
Expand Down
2 changes: 0 additions & 2 deletions modules/mfa/public/low-on-backup-codes.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
$globalConfig = Configuration::getInstance();

$t = new Template($globalConfig, 'mfa:low-on-backup-codes');
$t->data['theme_color_scheme'] = $globalConfig->getOptionalString('theme.color-scheme', null);
$t->data['analytics_tracking_id'] = $globalConfig->getOptionalString('analytics.trackingId', '');
$t->data['num_backup_codes_remaining'] = $state['numBackupCodesRemaining'];
$t->send();

Expand Down
2 changes: 0 additions & 2 deletions modules/mfa/public/must-set-up-mfa.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
$globalConfig = Configuration::getInstance();

$t = new Template($globalConfig, 'mfa:must-set-up-mfa');
$t->data['theme_color_scheme'] = $globalConfig->getOptionalString('theme.color-scheme', null);
$t->data['analytics_tracking_id'] = $globalConfig->getOptionalString('analytics.trackingId', '');
$t->send();

$logger->info(sprintf(
Expand Down
2 changes: 0 additions & 2 deletions modules/mfa/public/new-backup-codes.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
$globalConfig = Configuration::getInstance();

$t = new Template($globalConfig, 'mfa:new-backup-codes');
$t->data['theme_color_scheme'] = $globalConfig->getOptionalString('theme.color-scheme', null);
$t->data['analytics_tracking_id'] = $globalConfig->getOptionalString('analytics.trackingId', '');
$t->data['mfa_setup_url'] = $state['mfaSetupUrl'];
$t->data['new_backup_codes'] = $state['newBackupCodes'] ?? [];
$t->data['idp_name'] = $globalConfig->getString('idp_display_name');
Expand Down
2 changes: 0 additions & 2 deletions modules/mfa/public/out-of-backup-codes.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
$globalConfig = Configuration::getInstance();

$t = new Template($globalConfig, 'mfa:out-of-backup-codes');
$t->data['theme_color_scheme'] = $globalConfig->getOptionalString('theme.color-scheme', null);
$t->data['analytics_tracking_id'] = $globalConfig->getOptionalString('analytics.trackingId', '');
$t->data['has_other_mfa_options'] = $hasOtherMfaOptions;
$t->send();

Expand Down
2 changes: 0 additions & 2 deletions modules/mfa/public/prompt-for-mfa.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@
$mfaTemplateToUse = Mfa::getTemplateFor($mfaOption['type']);

$t = new Template($globalConfig, $mfaTemplateToUse);
$t->data['theme_color_scheme'] = $globalConfig->getOptionalString('theme.color-scheme', null);
$t->data['analytics_tracking_id'] = $globalConfig->getOptionalString('analytics.trackingId', '');
$t->data['error_message'] = $errorMessage ?? null;
$t->data['mfa_option_data'] = json_encode($mfaOption['data']);
$t->data['mfa_options'] = $mfaOptions;
Expand Down
2 changes: 0 additions & 2 deletions modules/mfa/public/send-manager-mfa.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
$globalConfig = Configuration::getInstance();

$t = new Template($globalConfig, 'mfa:send-manager-mfa');
$t->data['theme_color_scheme'] = $globalConfig->getOptionalString('theme.color-scheme', null);
$t->data['analytics_tracking_id'] = $globalConfig->getOptionalString('analytics.trackingId', '');
$t->data['manager_email'] = $state['managerEmail'];
$t->data['error_message'] = $errorMessage ?? null;
$t->send();
Expand Down
2 changes: 0 additions & 2 deletions modules/profilereview/public/nag.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
$globalConfig = Configuration::getInstance();

$t = new Template($globalConfig, 'profilereview:' . $state['template']);
$t->data['theme_color_scheme'] = $globalConfig->getOptionalString('theme.color-scheme', null);
$t->data['analytics_tracking_id'] = $globalConfig->getOptionalString('analytics.trackingId', '');
$t->data['profile_url'] = $state['profileUrl'];
$t->data['method_options'] = $state['methodOptions'] ?? [];
$t->data['mfa_options'] = $state['mfaOptions'] ?? [];
Expand Down
2 changes: 0 additions & 2 deletions modules/profilereview/public/review.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
$globalConfig = Configuration::getInstance();

$t = new Template($globalConfig, 'profilereview:review');
$t->data['theme_color_scheme'] = $globalConfig->getOptionalString('theme.color-scheme', null);
$t->data['analytics_tracking_id'] = $globalConfig->getOptionalString('analytics.trackingId', '');
$t->data['profile_url'] = $state['profileUrl'];
$t->data['method_options'] = $state['methodOptions'];
$t->data['mfa_options'] = $state['mfaOptions'];
Expand Down
2 changes: 0 additions & 2 deletions modules/silauth/public/loginuserpass.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@
}

$t = new Template($globalConfig, 'silauth:loginuserpass');
$t->data['theme_color_scheme'] = $globalConfig->getOptionalString('theme.color-scheme', null);
$t->data['analytics_tracking_id'] = $globalConfig->getOptionalString('analytics.trackingId', '');
$t->data['stateparams'] = array('AuthState' => $authStateId);
$t->data['username'] = $username;
$t->data['errorcode'] = $errorCode;
Expand Down

0 comments on commit 0dd3a9b

Please sign in to comment.