![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/extmag/shiplab/Helper/Config/Structure/ |
<?php /** * Copyright © Extmag. All rights reserved. */ namespace Extmag\Shiplab\Helper\Config\Structure; use Magento\Config\Model\Config\Structure\ElementVisibilityComposite; use Magento\Config\Model\Config\Structure\ElementVisibilityInterface; use Magento\Config\Model\Config\StructureElementInterface; use Magento\Framework\Module\Manager; use Magento\Framework\Phrase; use Magento\Store\Model\StoreManagerInterface; class AbstractElement implements StructureElementInterface { /** * Element data * * @var array */ protected $_data = []; /** * Current configuration scope * * @var string */ protected $_scope; /** * Store manager * * @var StoreManagerInterface */ protected $_storeManager; /** * @var Manager */ protected $moduleManager; /** * @var ElementVisibilityInterface */ private $elementVisibility; /** * @param StoreManagerInterface $storeManager * @param Manager $moduleManager * @param ElementVisibilityComposite $elementVisibility */ public function __construct( StoreManagerInterface $storeManager, Manager $moduleManager, ElementVisibilityComposite $elementVisibility ) { $this->_storeManager = $storeManager; $this->moduleManager = $moduleManager; $this->elementVisibility = $elementVisibility; } /** * Retrieve flyweight data * * @return array */ public function getData() { return $this->_data; } /** * Set element data * * @param array $data * @param string $scope * @return void */ public function setData(array $data, $scope) { $this->_data = $data; $this->_scope = $scope; } /** * Retrieve element label * * @return string */ public function getLabel() { return $this->_getTranslatedAttribute('label'); } /** * Translate element attribute * * @param string $code * @return Phrase|string */ protected function _getTranslatedAttribute($code) { if (!isset($this->_data[$code])) { return ''; } return __($this->_data[$code]); } /** * Retrieve element label * * @return string */ public function getComment() { return $this->_getTranslatedAttribute('comment'); } /** * Retrieve frontend model class name * * @return string */ public function getFrontendModel() { return $this->_data['frontend_model'] ?? ''; } /** * Retrieve arbitrary element attribute * * @param string $key * @return mixed */ public function getAttribute($key) { return $this->_data[$key] ?? null; } /** * Check whether element should be displayed * * @return bool */ public function isVisible() { if ($this->elementVisibility->isHidden($this->getPath())) { return false; } if (isset($this->_data['if_module_enabled']) && !$this->moduleManager->isOutputEnabled($this->_data['if_module_enabled'])) { return false; } $showInScope = [ 'store' => $this->_hasVisibilityValue('showInStore'), 'direction' => $this->_hasVisibilityValue('showInDirection'), 'country' => $this->_hasVisibilityValue('showInCountry'), 'default' => $this->_hasVisibilityValue('showInDefault'), ]; return !empty($showInScope[$this->_scope]); } /** * Retrieve element config path * * @param string $fieldPrefix * @return string */ public function getPath($fieldPrefix = '') { return $this->_getPath($this->getId(), $fieldPrefix); } /** * Retrieve config path for given id * * @param string $fieldId * @param string $fieldPrefix * @return string */ protected function _getPath($fieldId, $fieldPrefix = '') { $path = $this->_data['path'] ?? ''; return $path . '/' . $fieldPrefix . $fieldId; } /** * Retrieve element id * * @return string */ public function getId() { return $this->_data['id'] ?? ''; } /** * Retrieve value of visibility flag * * @param string $key * @return bool */ protected function _hasVisibilityValue($key) { return isset($this->_data[$key]) && $this->_data[$key]; } /** * Retrieve css class of a tab * * @return string */ public function getClass() { return $this->_data['class'] ?? ''; } }