Files
ltsecurityinc/app/code/Plumrocket/GlobalPrivacyControl/Block/Adminhtml/System/Config/GeoTargetingMultiSelect.php
T

89 lines
2.8 KiB
PHP

<?php
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc.
* @license https://plumrocket.com/license End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\GlobalPrivacyControl\Block\Adminhtml\System\Config;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Plumrocket\GeoIPLookup\Helper\Config;
class GeoTargetingMultiSelect extends \Magento\Config\Block\System\Config\Form\Field
{
/**
* @var \Plumrocket\GeoIPLookup\Helper\Config
*/
private $config;
/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Plumrocket\GeoIPLookup\Helper\Config $config
* @param array $data
*/
public function __construct(
Context $context,
Config $config,
array $data = []
) {
parent::__construct($context, $data);
$this->config = $config;
}
/**
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
*/
protected function _getElementHtml(AbstractElement $element)
{
return $this->getGeoIpRestrictionsNotice() . parent::_getElementHtml($element);
}
/**
* @param $withContainer
* @return \Magento\Framework\Phrase|string
*/
public function getGeoIpRestrictionsNotice($withContainer = true)
{
$message = '';
switch (true) {
case ! $this->config->isModuleEnabled():
$message = __(
'Geo Targeting is disabled. ' .
'For more accurate geolocation detection, please enable and configure the IP Geolocation Lookup extension following the <a target="_blank" href="%1">guide</a>.',
'https://plumrocket.com/docs/magento-ip-geolocation-lookup/v2/configuration'
);
break;
case ! $this->config->getEnableMethodsNumber():
$message = __(
'Please enable at least one IP Geolocation Lookup database to use Geo Targeting. ' .
'Click <a target="_blank" href="%1">here</a> for configuration guide.',
'https://plumrocket.com/docs/magento-ip-geolocation-lookup/v2/configuration'
);
break;
}
return (bool) $withContainer && ! empty($message)
? $this->getPreparedNoticeHtml($message)
: $message;
}
/**
* @param $message
* @return string
*/
public function getPreparedNoticeHtml($message): string
{
$style = 'style="margin: 25px 5px;color: #eb5202;background: none;font-size:14px"';
return "<div $style><div><i>$message</i></div></div>";
}
}