diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b9bbb36 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2022 Peter Rusin + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/Model/Config.php b/Model/Config.php new file mode 100644 index 0000000..1f09b58 --- /dev/null +++ b/Model/Config.php @@ -0,0 +1,48 @@ +scopeConfig = $scopeConfig; + } + + /** + * @return bool + */ + public function isEnabled() : bool + { + return $this->scopeConfig->isSetFlag(self::ENABLED_XML_PATH); + } + + /** + * @return bool + */ + public function isSortOrdersEnabled() : bool + { + return $this->scopeConfig->isSetFlag(self::SORT_ORDERS_ENABLED_XML_PATH); + } + + /** + * @return bool + */ + public function isPathsEnabled() : bool + { + return $this->scopeConfig->isSetFlag(self::PATHS_ENABLED_XML_PATH); + } +} diff --git a/Plugin/AddConfigPathToCommentPlugin.php b/Plugin/AddConfigPathToCommentPlugin.php new file mode 100644 index 0000000..54735b3 --- /dev/null +++ b/Plugin/AddConfigPathToCommentPlugin.php @@ -0,0 +1,44 @@ +config = $config; + } + + /** + * @param Field $subject + * @param string $result + * @return string + */ + public function afterGetComment(Field $subject, string $result): string + { + if (!$this->config->isEnabled() || !$this->config->isPathsEnabled()) { + return $result; + } + + $data = $subject->getData(); + $prefix = strlen($result) > 0 ? "

" : ""; + + $result .= $prefix . $subject->getPath(); + + if (isset($data['comment']['model'])) { + $result .= "
Comment model: {$data['comment']['model']}"; + } + + return $result; + } +} diff --git a/Plugin/AddSortOrderToLabelsPlugin.php b/Plugin/AddSortOrderToLabelsPlugin.php new file mode 100644 index 0000000..bcad9bf --- /dev/null +++ b/Plugin/AddSortOrderToLabelsPlugin.php @@ -0,0 +1,64 @@ +config = $config; + } + + /** + * @param Converter $subject + * @param array $result + * @return array + */ + public function afterConvert(Converter $subject, array $result): array + { + if (!$this->config->isEnabled() || !$this->config->isSortOrdersEnabled()) { + return $result; + } + + $result['config']['system']['tabs'] = $this->processFields( + $result['config']['system']['tabs'] ?? [] + ); + $result['config']['system']['sections'] = $this->processFields( + $result['config']['system']['sections'] ?? [] + ); + + return $result; + } + + /** + * @param $components + * @return array + */ + protected function processFields($components): array + { + foreach ($components as $key => $element) { + if (isset($element['sortOrder'])) { + $element['label'] = sprintf( + '%s | 🔀 %s', + $element['label'] ?? '', + $element['sortOrder'], + ); + } + + if (isset($element['children'])) { + $element['children'] = $this->processFields($element['children']); + } + + $components[$key] = $element; + } + + return $components; + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..9961735 --- /dev/null +++ b/README.md @@ -0,0 +1,58 @@ +# System Configuration Toolkit + +System Configuration Toolkit is a Magento 2 module that shows sort order of system configuration's tabs, sections, groups, and fields. + +It also helps you to see full field paths, so no more looking for those. + +**Disclaimer:** System Configuration Toolkit sole purpose is to speed up the process of adding new System Configuration during development. + +There is no use case for live / production environments, and this module shouldn't really be installed there. + +## Installation +``` +composer require --dev pragmatic-modules/magento2-module-system-configuration-toolkit +bin/magento module:enable Pragmatic_SystemConfigurationToolkit +bin/magento setup:upgrade +``` + +## Configuration + +In order to module take effect you have to enable it through + +`Store > Configuration > Pragmatic Modules > System Configuration Toolkit > General > Enable` + +You can enable functionalities separately to display + +1. sort orders of tabs, sections, groups, and fields +2. field full path + +Once you enable it, you have to clear `config` cache type by running `bin/magento cache:clean config` + +## Problem + +It is quite common to add new system configurations for custom modules during development. + +To do that, you have to determine *where* it should be displayed through adjusting `sortOrder` to the value that's in between the already existing tabs, and sections. + +You can find sort orders in `system.xml` but because each module has its own separate `system.xml` it becomes a pain to find proper sort order of tabs and sections. The same problem applies to any adjustments to the existing system configuration. + +When your job is to add a new field(s) to an existing group below some other field it can become a guessing game, sort order flipping, and cache refreshing, until the field finally lands where it is supposed to be. + +## Solution + +System Configuration Toolkit module that will help save you time that you would normally spend on looking for `system.xml` sort orders or full paths. + + +## How It Looks + +#### Before: + +![](before.png) + +#### After: + +![](after.png) + +## How It Works + +System Configuration Toolkit is using two plugins: (1) for sort orders that are appended into the tabs, sections, groups, and field labels, (2) for field paths that are appended into field comment diff --git a/after.png b/after.png new file mode 100644 index 0000000..8bee23a Binary files /dev/null and b/after.png differ diff --git a/before.png b/before.png new file mode 100644 index 0000000..9b02617 Binary files /dev/null and b/before.png differ diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..9e7e73b --- /dev/null +++ b/composer.json @@ -0,0 +1,26 @@ +{ + "name": "pragmatic/magento2-module-system-configuration-toolkit", + "description": "System Configuration Toolkit is a Magento 2 module that shows sort order of system configuration's tabs, sections, groups, and fields. It also helps you to see full field paths, so no more looking for those.", + "type": "magento2-module", + "homepage": "https://rusin.work", + "license": "MIT", + "authors": [ + { + "name": "Peter Rusin", + "email": "peter@rusin.work", + "homepage": "https://rusin.work", + "role": "Senior Magento Developer" + } + ], + "require": { + "magento/framework": "*" + }, + "autoload": { + "files": [ + "registration.php" + ], + "psr-4": { + "Pragmatic\\SystemConfigurationToolkit\\": "" + } + } +} diff --git a/etc/adminhtml/di.xml b/etc/adminhtml/di.xml new file mode 100644 index 0000000..869f65b --- /dev/null +++ b/etc/adminhtml/di.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml new file mode 100644 index 0000000..8098028 --- /dev/null +++ b/etc/adminhtml/system.xml @@ -0,0 +1,35 @@ + + + + + + +
+ + Magento_Config::config + pragmatic + + + + + Magento\Config\Model\Config\Source\Yesno + + + + Magento\Config\Model\Config\Source\Yesno + You must clear config cache type after toggling this value in order to changes to take effect. + + 1 + + + + + Magento\Config\Model\Config\Source\Yesno + + 1 + + + +
+
+
diff --git a/etc/module.xml b/etc/module.xml new file mode 100644 index 0000000..2a1ff66 --- /dev/null +++ b/etc/module.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/registration.php b/registration.php new file mode 100644 index 0000000..4bc775c --- /dev/null +++ b/registration.php @@ -0,0 +1,6 @@ +