|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +/** |
| 8 | + * System config email field backend model |
| 9 | + */ |
| 10 | +declare(strict_types=1); |
| 11 | + |
| 12 | +namespace Magento\Security\Block\Config\Backend\Session; |
| 13 | + |
| 14 | +use Magento\Backend\Block\Template\Context; |
| 15 | +use Magento\Config\Block\System\Config\Form\Field; |
| 16 | +use Magento\Framework\Data\Form\Element\AbstractElement; |
| 17 | +use Magento\Framework\Exception\ValidatorException; |
| 18 | +use Magento\Framework\Serialize\Serializer\Json; |
| 19 | + |
| 20 | +/** |
| 21 | + * Backend Model for Max Session Size |
| 22 | + */ |
| 23 | +class SessionSize extends Field |
| 24 | +{ |
| 25 | + /** |
| 26 | + * @var Json |
| 27 | + */ |
| 28 | + private $json; |
| 29 | + |
| 30 | + /** |
| 31 | + * @param Context $context |
| 32 | + * @param Json $json |
| 33 | + * @param array $data |
| 34 | + */ |
| 35 | + public function __construct( |
| 36 | + Context $context, |
| 37 | + Json $json, |
| 38 | + array $data = [] |
| 39 | + ) { |
| 40 | + parent::__construct($context, $data); |
| 41 | + $this->json = $json; |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * {@inheritdoc} |
| 46 | + * @throws ValidatorException |
| 47 | + */ |
| 48 | + protected function _getElementHtml(AbstractElement $element) |
| 49 | + { |
| 50 | + $html = parent::_getElementHtml($element); |
| 51 | + $originalData = $element->getOriginalData(); |
| 52 | + $maxSessionSizeAdminSelector = '#' . $element->getHtmlId(); |
| 53 | + $jsString = '<script type="text/x-magento-init"> {"' . |
| 54 | + $maxSessionSizeAdminSelector . '": { |
| 55 | + "Magento_Security/js/system/config/session-size": {"modalTitleText": ' . |
| 56 | + $this->json->serialize(__($originalData['modal_title_text'])) . ', "modalContentBody": ' . |
| 57 | + $this->json->serialize($this->getModalContentBody($originalData['modal_content_body_path'])) |
| 58 | + . '}}}</script>'; |
| 59 | + |
| 60 | + $html .= $jsString; |
| 61 | + return $html; |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * Get HTML for the modal content body when user switches to disable |
| 66 | + * |
| 67 | + * @param string $templatePath |
| 68 | + * @return string |
| 69 | + * @throws ValidatorException |
| 70 | + */ |
| 71 | + private function getModalContentBody(string $templatePath) |
| 72 | + { |
| 73 | + $templateFileName = $this->getTemplateFile($templatePath); |
| 74 | + |
| 75 | + return $this->fetchView($templateFileName); |
| 76 | + } |
| 77 | +} |
0 commit comments