-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Peter Rusin
committed
Feb 12, 2022
0 parents
commit 2813118
Showing
12 changed files
with
320 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Pragmatic\SystemConfigurationToolkit\Model; | ||
|
||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
|
||
class Config | ||
{ | ||
const ENABLED_XML_PATH = 'system_configuration_toolkit/general/enabled'; | ||
const SORT_ORDERS_ENABLED_XML_PATH = 'system_configuration_toolkit/general/sort_orders_enabled'; | ||
const PATHS_ENABLED_XML_PATH = 'system_configuration_toolkit/general/paths_enabled'; | ||
|
||
/** @var ScopeConfigInterface */ | ||
private $scopeConfig; | ||
|
||
/** | ||
* @param ScopeConfigInterface $scopeConfig | ||
*/ | ||
public function __construct(ScopeConfigInterface $scopeConfig) | ||
{ | ||
$this->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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Pragmatic\SystemConfigurationToolkit\Plugin; | ||
|
||
use Magento\Config\Model\Config\Structure\Element\Field; | ||
use Pragmatic\SystemConfigurationToolkit\Model\Config; | ||
|
||
class AddConfigPathToCommentPlugin | ||
{ | ||
/** @var Config */ | ||
private $config; | ||
|
||
/** | ||
* @param Config $config | ||
*/ | ||
public function __construct(Config $config) | ||
{ | ||
$this->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 ? "<br><br>" : ""; | ||
|
||
$result .= $prefix . $subject->getPath(); | ||
|
||
if (isset($data['comment']['model'])) { | ||
$result .= "<br>Comment model: {$data['comment']['model']}"; | ||
} | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Pragmatic\SystemConfigurationToolkit\Plugin; | ||
|
||
use Magento\Config\Model\Config\Structure\Converter; | ||
use Pragmatic\SystemConfigurationToolkit\Model\Config; | ||
|
||
class AddSortOrderToLabelsPlugin | ||
{ | ||
/** @var Config */ | ||
private $config; | ||
|
||
public function __construct(Config $config) | ||
{ | ||
$this->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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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\\": "" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
<type name="Magento\Config\Model\Config\Structure\Converter"> | ||
<plugin name="Pragmatic_SystemConfigurationToolkit::add_sort_order_to_labels" | ||
type="Pragmatic\SystemConfigurationToolkit\Plugin\AddSortOrderToLabelsPlugin"/> | ||
</type> | ||
<type name="Magento\Config\Model\Config\Structure\Element\Field"> | ||
<plugin name="Pragmatic_SystemConfigurationToolkit::add_config_path_to_comment" | ||
type="Pragmatic\SystemConfigurationToolkit\Plugin\AddConfigPathToCommentPlugin"/> | ||
</type> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd"> | ||
<system> | ||
<tab id="pragmatic" translate="label" sortOrder="600"> | ||
<label>Pragmatic Modules</label> | ||
</tab> | ||
<section id="system_configuration_toolkit" showInDefault="1" translate="label" sortOrder="50"> | ||
<label>System Configuration Toolkit</label> | ||
<resource>Magento_Config::config</resource> | ||
<tab>pragmatic</tab> | ||
<group id="general" showInDefault="1" translate="label"> | ||
<label>General</label> | ||
<field id="enabled" type="select" showInDefault="1" translate="label"> | ||
<label>Enabled</label> | ||
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model> | ||
</field> | ||
<field id="sort_orders_enabled" type="select" showInDefault="1" translate="label"> | ||
<label>Show Tabs/Sections/Groups/Fields sort order?</label> | ||
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model> | ||
<comment>You must clear config cache type after toggling this value in order to changes to take effect.</comment> | ||
<depends> | ||
<field id="enabled">1</field> | ||
</depends> | ||
</field> | ||
<field id="paths_enabled" type="select" showInDefault="1" translate="label"> | ||
<label>Show field's config path in the comments</label> | ||
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model> | ||
<depends> | ||
<field id="enabled">1</field> | ||
</depends> | ||
</field> | ||
</group> | ||
</section> | ||
</system> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> | ||
<module name="Pragmatic_SystemConfigurationToolkit"> | ||
<sequence> | ||
<module name="Magento_Config"/> | ||
</sequence> | ||
</module> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
use Magento\Framework\Component\ComponentRegistrar; | ||
|
||
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Pragmatic_SystemConfigurationToolkit', __DIR__); |