From d7d6c5bbe45d12df5f2cc59345d750c0db33fa80 Mon Sep 17 00:00:00 2001 From: Renon Stewart Date: Sat, 7 Oct 2017 22:36:43 -0400 Subject: [PATCH] Add support for 2.2 --- .../System/Config/Form/Composer/Version.php | 121 ++++++++++++++++++ .../Config/{ => Form/Module}/Version.php | 4 +- composer.json | 4 +- etc/adminhtml/system.xml | 17 ++- 4 files changed, 137 insertions(+), 9 deletions(-) create mode 100644 Block/Adminhtml/System/Config/Form/Composer/Version.php rename Block/Adminhtml/System/Config/{ => Form/Module}/Version.php (93%) diff --git a/Block/Adminhtml/System/Config/Form/Composer/Version.php b/Block/Adminhtml/System/Config/Form/Composer/Version.php new file mode 100644 index 0000000..158b30f --- /dev/null +++ b/Block/Adminhtml/System/Config/Form/Composer/Version.php @@ -0,0 +1,121 @@ +deploymentConfig = $deploymentConfig; + $this->componentRegistrar = $componentRegistrar; + $this->readFactory = $readFactory; + parent::__construct($context, $data); + } + + /** + * Render button + * + * @param \Magento\Framework\Data\Form\Element\AbstractElement $element + * @return string + */ + public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element) + { + // Remove scope label + $element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue(); + return parent::render($element); + } + + + /** + * Return element html + * + * @param \Magento\Framework\Data\Form\Element\AbstractElement $element + * @return string + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element) + { + return 'v' . $this->getVersion(); + } + + + /** + * Get Module version number + * + * @return string + */ + public function getVersion(){ + return $this->getComposerVersion($this->getModuleName()); + } + + /** + * @return string + */ + public function getModuleName() + { + $classArray = explode('\\', get_class($this)); + + return count($classArray) > 2 ? "{$classArray[0]}_{$classArray[1]}" : ''; + } + + /** + * Get module composer version + * + * @param $moduleName + * @return \Magento\Framework\Phrase|string|void + */ + public function getComposerVersion($moduleName) + { + $path = $this->componentRegistrar->getPath( + \Magento\Framework\Component\ComponentRegistrar::MODULE, + $moduleName + ); + + try{ + $directoryRead = $this->readFactory->create($path); + $composerJsonData = $directoryRead->readFile('composer.json'); + + if($composerJsonData){ + $data = json_decode($composerJsonData); + return !empty($data->version) ? $data->version : __('Unknown'); + } + + } + catch (\Exception $e){ + // + } + + return 'Unknown'; + + } +} diff --git a/Block/Adminhtml/System/Config/Version.php b/Block/Adminhtml/System/Config/Form/Module/Version.php similarity index 93% rename from Block/Adminhtml/System/Config/Version.php rename to Block/Adminhtml/System/Config/Form/Module/Version.php index 343dcce..41e39f8 100644 --- a/Block/Adminhtml/System/Config/Version.php +++ b/Block/Adminhtml/System/Config/Form/Module/Version.php @@ -1,10 +1,10 @@ Catalog Lazy Load magepal MagePal_CatalogLazyLoad::cataloglazyload - - - - - MagePal\CatalogLazyLoad\Block\Adminhtml\System\Config\Version + + + + + MagePal\CatalogLazyLoad\Block\Adminhtml\System\Config\Form\Module\Version + + + + MagePal\CatalogLazyLoad\Block\Adminhtml\System\Config\Form\Composer\Version + + + Magento\Config\Model\Config\Source\Yesno