From c8794729265b3618de84f15b6ffaed5454422145 Mon Sep 17 00:00:00 2001 From: Brett Laishley Date: Tue, 7 Oct 2025 14:42:32 +1030 Subject: [PATCH 1/5] BEG-223: Add session expiry warning modal --- Block/Adminhtml/Modal.php | 43 +++++++++++++++ .../layout/adminhtml_dashboard_index.xml | 8 +++ view/adminhtml/templates/modal.phtml | 54 +++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 Block/Adminhtml/Modal.php create mode 100644 view/adminhtml/layout/adminhtml_dashboard_index.xml create mode 100644 view/adminhtml/templates/modal.phtml diff --git a/Block/Adminhtml/Modal.php b/Block/Adminhtml/Modal.php new file mode 100644 index 0000000..4c4ae2d --- /dev/null +++ b/Block/Adminhtml/Modal.php @@ -0,0 +1,43 @@ +_scopeConfig->getValue( + 'admin/security/session_lifetime', + ScopeConfigInterface::SCOPE_TYPE_DEFAULT + ); + + // We want the popup to appear one minute before the timeout (in ms) + return ($sessionTimeout - 60) * 1000; + } +} diff --git a/view/adminhtml/layout/adminhtml_dashboard_index.xml b/view/adminhtml/layout/adminhtml_dashboard_index.xml new file mode 100644 index 0000000..e381ae8 --- /dev/null +++ b/view/adminhtml/layout/adminhtml_dashboard_index.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/view/adminhtml/templates/modal.phtml b/view/adminhtml/templates/modal.phtml new file mode 100644 index 0000000..4bbdd9d --- /dev/null +++ b/view/adminhtml/templates/modal.phtml @@ -0,0 +1,54 @@ +getModalPopupTimeout(); + +?> + +
+

+

Your admin session will expire in one minute, please save your changes or refresh the page.

+
+ + From a519cccd12726b0928f01183c8c6afbd115779f7 Mon Sep 17 00:00:00 2001 From: Brett Laishley Date: Tue, 7 Oct 2025 17:50:10 +1030 Subject: [PATCH 2/5] BEG-223: Move to ALL admin views, and use ViewModel --- {Block/Adminhtml => ViewModel}/Modal.php | 20 +++++++------------ ...inhtml_dashboard_index.xml => default.xml} | 2 +- view/adminhtml/templates/modal.phtml | 10 +++++++--- 3 files changed, 15 insertions(+), 17 deletions(-) rename {Block/Adminhtml => ViewModel}/Modal.php (52%) rename view/adminhtml/layout/{adminhtml_dashboard_index.xml => default.xml} (77%) diff --git a/Block/Adminhtml/Modal.php b/ViewModel/Modal.php similarity index 52% rename from Block/Adminhtml/Modal.php rename to ViewModel/Modal.php index 4c4ae2d..412c05d 100644 --- a/Block/Adminhtml/Modal.php +++ b/ViewModel/Modal.php @@ -2,26 +2,20 @@ declare(strict_types=1); -namespace Aligent\Pci4Compatibility\Block\Adminhtml; +namespace Aligent\Pci4Compatibility\ViewModel; -use Magento\Backend\Block\Template; -use Magento\Backend\Block\Template\Context; use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\View\Element\Block\ArgumentInterface; -class Modal extends Template +class Modal implements ArgumentInterface { /** * Constructor - * @param Context $context * @param ScopeConfigInterface $scopeConfig - * @param array $data */ public function __construct( - Context $context, - ScopeConfigInterface $scopeConfig, - array $data = [] + private readonly ScopeConfigInterface $scopeConfig, ) { - parent::__construct($context, $data); } /** @@ -31,13 +25,13 @@ public function __construct( */ public function getModalPopupTimeout(): int { - // Session lifetime in seconds - $sessionTimeout = $this->_scopeConfig->getValue( + // This value is in seconds + $sessionTimeout = $this->scopeConfig->getValue( 'admin/security/session_lifetime', ScopeConfigInterface::SCOPE_TYPE_DEFAULT ); - // We want the popup to appear one minute before the timeout (in ms) + // Then we want the popup to appear one minute before timeout return ($sessionTimeout - 60) * 1000; } } diff --git a/view/adminhtml/layout/adminhtml_dashboard_index.xml b/view/adminhtml/layout/default.xml similarity index 77% rename from view/adminhtml/layout/adminhtml_dashboard_index.xml rename to view/adminhtml/layout/default.xml index e381ae8..2be2a3b 100644 --- a/view/adminhtml/layout/adminhtml_dashboard_index.xml +++ b/view/adminhtml/layout/default.xml @@ -2,7 +2,7 @@ - + diff --git a/view/adminhtml/templates/modal.phtml b/view/adminhtml/templates/modal.phtml index 4bbdd9d..9d3581b 100644 --- a/view/adminhtml/templates/modal.phtml +++ b/view/adminhtml/templates/modal.phtml @@ -1,14 +1,18 @@ getModalPopupTimeout(); +$viewModel = $block->getViewModel(); +$modalTimeout = $viewModel->getModalPopupTimeout(); ?> @@ -46,7 +50,7 @@ $sessionTimeout = $block->getModalPopupTimeout(); function() { $('#session-expire-warning-modal').modal('openModal') }, - + ); }); } From 8e8e90ad33784c27f27e9806a1471372cdd5f9ad Mon Sep 17 00:00:00 2001 From: Brett Laishley Date: Tue, 7 Oct 2025 17:53:17 +1030 Subject: [PATCH 3/5] BEG-223: Delete renamed variable --- view/adminhtml/templates/modal.phtml | 2 -- 1 file changed, 2 deletions(-) diff --git a/view/adminhtml/templates/modal.phtml b/view/adminhtml/templates/modal.phtml index 9d3581b..18d0c8d 100644 --- a/view/adminhtml/templates/modal.phtml +++ b/view/adminhtml/templates/modal.phtml @@ -9,8 +9,6 @@ use Magento\Framework\Escaper; * @var Escaper $escaper * @var Modal $viewModel */ - -$sessionTimeout = $block->getModalPopupTimeout(); $viewModel = $block->getViewModel(); $modalTimeout = $viewModel->getModalPopupTimeout(); From ac78bb815905b996e60239412b59d555b4ac6da0 Mon Sep 17 00:00:00 2001 From: Brett Laishley Date: Wed, 8 Oct 2025 11:42:15 +1030 Subject: [PATCH 4/5] BEG-223: Add view_model to block arguments and update class --- view/adminhtml/layout/default.xml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/view/adminhtml/layout/default.xml b/view/adminhtml/layout/default.xml index 2be2a3b..d286eb4 100644 --- a/view/adminhtml/layout/default.xml +++ b/view/adminhtml/layout/default.xml @@ -2,7 +2,11 @@ - + + + Aligent\Pci4Compatibility\ViewModel\Modal + + From f388141ef781b605504d133e67c4ac1dc3263c80 Mon Sep 17 00:00:00 2001 From: Brett Laishley Date: Wed, 8 Oct 2025 11:42:39 +1030 Subject: [PATCH 5/5] BEG-223: Improve docblock wording choice --- ViewModel/Modal.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ViewModel/Modal.php b/ViewModel/Modal.php index 412c05d..65606be 100644 --- a/ViewModel/Modal.php +++ b/ViewModel/Modal.php @@ -19,7 +19,7 @@ public function __construct( } /** - * Returns the time in ms after refresh when the session expiry warning modal should appear + * Returns the duration in ms after refresh when the session expiry warning modal should appear * * @return int */