C3_ConfigSetupHelper - Version 1.0.1

Version Notes

Features:


  • Speed up development - ready to copy and paste into a setup script and save

  • Works with any extension that displays options in the system config

  • Self-commenting: Gives section and group names to aid visibility

Known issues:


  • There are some settings in e.g. Paypal that aren’t currently outputting correctly. We are looking into this for the next version.

  • Oldest supported CE version is 1.7.0.1

Download this release

Release Info

Developer C3 Media
Extension C3_ConfigSetupHelper
Version 1.0.1
Comparing to
See all releases


Version 1.0.1

app/code/local/C3/ConfigSetupHelper/Block/System/Config/Form/Field.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Abstract config form element renderer
4
+ *
5
+ * @category Mage
6
+ * @package Mage_Adminhtml
7
+ * @author Magento Core Team <core@magentocommerce.com>
8
+ */
9
+ class C3_ConfigSetupHelper_Block_System_Config_Form_Field
10
+ extends Mage_Adminhtml_Block_System_Config_Form_Field
11
+ {
12
+ /**
13
+ * Decorate field row html
14
+ * @modification Add checkbox to mark which fields we want to output
15
+ *
16
+ * @param Varien_Data_Form_Element_Abstract $element
17
+ * @param string $html
18
+ * @return string
19
+ */
20
+ protected function _decorateRowHtml($element, $html)
21
+ {
22
+ // If enabled, add checkboxes to this field
23
+ if (Mage::getStoreConfig('c3_configsetuphelper/options/enabled')) {
24
+ // Change name so that it is different to the actual values being saved
25
+ $namePrefix = preg_replace('#\[value\](\[\])?$#', '', $element->getName());
26
+ $namePrefix = preg_replace('#^groups#', 'show_config', $namePrefix);
27
+
28
+ $extraInput = "<input type=\"checkbox\" name=\"{$namePrefix}\" value=\"1\" style=\"float:left;margin-right:6px\" />";
29
+ $html = preg_replace('/^(<td[^>]*>)/', "$1{$extraInput}", $html);
30
+ }
31
+
32
+ return parent::_decorateRowHtml($element, $html);
33
+ }
34
+ }
app/code/local/C3/ConfigSetupHelper/Helper/Data.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Default Helper - Currently just so that translations will work
5
+ */
6
+ class C3_ConfigSetupHelper_Helper_Data extends Mage_Core_Helper_Abstract
7
+ {
8
+ }
app/code/local/C3/ConfigSetupHelper/Model/Observer.php ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Observer for config setup helper
5
+ */
6
+ class C3_ConfigSetupHelper_Model_Observer
7
+ {
8
+ /**
9
+ * Display config entries (as passed by form) in notification area ready to add to setup script
10
+ *
11
+ * @param $ob
12
+ */
13
+ public function showSelectedConfig($ob)
14
+ {
15
+ // If not enabled, or if no checkboxes ticked, skip
16
+ if (!Mage::getStoreConfig('c3_configsetuphelper/options/enabled') || !isset($_REQUEST['show_config'])) {
17
+ return;
18
+ }
19
+
20
+ // Helper for translations
21
+ $helper = Mage::helper('c3_configsetuphelper');
22
+
23
+ $website = $ob->getWebsite();
24
+ $store = $ob->getStore();
25
+ $section = $ob->getSection();
26
+
27
+ // Get fully qualified field names from form
28
+ $paths = array();
29
+ foreach (Mage::app()->getRequest()->getParam('show_config') as $groupname => $group) {
30
+ foreach (array_keys($group['fields']) as $fieldname) {
31
+ $fullName = "{$section}/{$groupname}/{$fieldname}";
32
+ $paths[] = $fullName;
33
+ }
34
+ }
35
+
36
+ // Get path values with correct scope
37
+ $pathValues = $this->_getPathValues($paths, $website, $store);
38
+
39
+ // Output values in string per group
40
+ $string = '<pre>' . $this->_getHeader() . '// ' . $helper->__('Config for') . ' ' . $helper->__($section) . "\n";
41
+ foreach (Mage::app()->getRequest()->getParam('show_config') as $groupname => $group) {
42
+ $string .= "\n// " . $helper->__('Settings for %s group', "'".$groupname."'"). "\n";
43
+ foreach (array_keys($group['fields']) as $fieldname) {
44
+ $fullName = "{$section}/{$groupname}/{$fieldname}";
45
+ // Skip if name was not retrieved
46
+ if (!isset($pathValues[$fullName])) {
47
+ continue;
48
+ }
49
+ $showVal = "'" . addslashes($pathValues[$fullName]) . "'";
50
+ if ($pathValues[$fullName] === null) {
51
+ $showVal = 'null';
52
+ }
53
+ $string .= "\$installer->setConfigData('" . addslashes($fullName) . "', $showVal);\n";
54
+ }
55
+ }
56
+ $string .= $this->_getFooter() . '</pre>';
57
+
58
+ // Output as notice to session
59
+ Mage::getSingleton('adminhtml/session')->addNotice(Mage::helper('adminhtml')->__($string));
60
+ }
61
+
62
+ /**
63
+ * @return string
64
+ */
65
+ protected function _getHeader()
66
+ {
67
+ return '/* @var $installer Mage_Core_Model_Resource_Setup */
68
+ $installer = $this;
69
+
70
+ $installer->startSetup();
71
+
72
+ ';
73
+ }
74
+
75
+ /**
76
+ * @return string
77
+ */
78
+ protected function _getFooter()
79
+ {
80
+ return '$installer->endSetup();';
81
+ }
82
+
83
+ /**
84
+ * Get config values for given paths from database
85
+ *
86
+ * @param array $paths
87
+ * @param null|string $website
88
+ * @param null|string $store
89
+ * @return object
90
+ */
91
+ protected function _getPathValues($paths, $website=null, $store=null)
92
+ {
93
+ // Get collection with correct scope and paths
94
+ $collection = Mage::getModel('core/config_data')->getCollection();
95
+ if ($store !== null) {
96
+ $collection->addFieldToFilter('scope','store');
97
+ $collection->addFieldToFilter('scope_id',$store);
98
+ } elseif ($website !== null) {
99
+ $collection->addFieldToFilter('scope','website');
100
+ $collection->addFieldToFilter('scope_id',$website);
101
+ } else {
102
+ $collection->addFieldToFilter('scope','default');
103
+ }
104
+ $collection->addFieldToFilter('path', array('in' => $paths));
105
+
106
+ // Get value per path
107
+ $pathValues = array();
108
+ foreach ($collection as $configrow) {
109
+ $pathValues[$configrow['path']] = $configrow['value'];
110
+ }
111
+
112
+ return $pathValues;
113
+ }
114
+ }
app/code/local/C3/ConfigSetupHelper/etc/adminhtml.xml ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * C3 Media Ltd
5
+ *
6
+ * @title Config Setup Helper
7
+ * @category C3
8
+ * @package C3_ConfigSetupHelper
9
+ * @author C3 Development Team <development@c3media.co.uk>
10
+ * @copyright Copyright (c) 2014 C3 Media Ltd (http://www.c3media.co.uk)
11
+ */
12
+ -->
13
+
14
+ <config>
15
+ <acl>
16
+ <resources>
17
+ <all>
18
+ <title>Allow Everything</title>
19
+ </all>
20
+ <admin>
21
+ <children>
22
+ <system>
23
+ <children>
24
+ <config>
25
+ <children>
26
+ <c3_configsetuphelper>
27
+ <title>Config Setup Helper</title>
28
+ <sort_order>10</sort_order>
29
+ </c3_configsetuphelper>
30
+ </children>
31
+ </config>
32
+ </children>
33
+ </system>
34
+ </children>
35
+ </admin>
36
+ </resources>
37
+ </acl>
38
+ </config>
app/code/local/C3/ConfigSetupHelper/etc/config.xml ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * C3 Media Ltd
5
+ *
6
+ * @title Config Setup Helper
7
+ * @category C3
8
+ * @package C3_ConfigSetupHelper
9
+ * @author C3 Development Team <development@c3media.co.uk>
10
+ * @copyright Copyright (c) 2014 C3 Media Ltd (http://www.c3media.co.uk)
11
+ */
12
+ -->
13
+ <config>
14
+ <modules>
15
+ <C3_ConfigSetupHelper>
16
+ <version>1.0.1</version>
17
+ </C3_ConfigSetupHelper>
18
+ </modules>
19
+ <global>
20
+ <models>
21
+ <c3_configsetuphelper>
22
+ <class>C3_ConfigSetupHelper_Model</class>
23
+ </c3_configsetuphelper>
24
+ </models>
25
+ <helpers>
26
+ <c3_configsetuphelper>
27
+ <class>C3_ConfigSetupHelper_Helper</class>
28
+ </c3_configsetuphelper>
29
+ </helpers>
30
+ <blocks>
31
+ <c3_configsetuphelper>
32
+ <class>C3_ConfigSetupHelper_Blocks</class>
33
+ </c3_configsetuphelper>
34
+ <adminhtml>
35
+ <rewrite>
36
+ <system_config_form_field>C3_ConfigSetupHelper_Block_System_Config_Form_Field</system_config_form_field>
37
+ </rewrite>
38
+ </adminhtml>
39
+ </blocks>
40
+ </global>
41
+ <adminhtml>
42
+ <translate>
43
+ <modules>
44
+ <C3_ConfigSetupHelper>
45
+ <files>
46
+ <default>C3_ConfigSetupHelper.csv</default>
47
+ </files>
48
+ </C3_ConfigSetupHelper>
49
+ </modules>
50
+ </translate>
51
+ <events>
52
+ <admin_system_config_section_save_after>
53
+ <observers>
54
+ <c3_configsetuphelper>
55
+ <type>singleton</type>
56
+ <class>c3_configsetuphelper/observer</class>
57
+ <method>showSelectedConfig</method>
58
+ </c3_configsetuphelper>
59
+ </observers>
60
+ </admin_system_config_section_save_after>
61
+ </events>
62
+ <acl>
63
+ <resources>
64
+ <admin>
65
+ <children>
66
+ <system>
67
+ <children>
68
+ <config>
69
+ <children>
70
+ <c3_configsetuphelper>
71
+ <title>Configuration for Config Setup Helper</title>
72
+ </c3_configsetuphelper>
73
+ </children>
74
+ </config>
75
+ </children>
76
+ </system>
77
+ </children>
78
+ </admin>
79
+ </resources>
80
+ </acl>
81
+ </adminhtml>
82
+ <default>
83
+ <c3_configsetuphelper>
84
+ <options>
85
+ <enabled>1</enabled>
86
+ </options>
87
+ </c3_configsetuphelper>
88
+ </default>
89
+ </config>
app/code/local/C3/ConfigSetupHelper/etc/system.xml ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <tabs>
3
+ <c3extensions translate="label">
4
+ <label>C3 Extensions</label>
5
+ <sort_order>900</sort_order>
6
+ <show_in_default>1</show_in_default>
7
+ <show_in_website>1</show_in_website>
8
+ <show_in_store>1</show_in_store>
9
+ </c3extensions>
10
+ </tabs>
11
+ <sections>
12
+ <c3_configsetuphelper translate="label" module="c3_configsetuphelper">
13
+ <label>Config Setup Helper</label>
14
+ <tab>c3extensions</tab>
15
+ <frontend_type>text</frontend_type>
16
+ <sort_order>600</sort_order>
17
+ <show_in_default>1</show_in_default>
18
+ <show_in_website>1</show_in_website>
19
+ <show_in_store>1</show_in_store>
20
+ <groups>
21
+ <options translate="label">
22
+ <label>Options</label>
23
+ <frontend_type>text</frontend_type>
24
+ <sort_order>1</sort_order>
25
+ <show_in_default>1</show_in_default>
26
+ <show_in_website>1</show_in_website>
27
+ <show_in_store>1</show_in_store>
28
+ <fields>
29
+ <enabled>
30
+ <label>Enable</label>
31
+ <frontend_type>select</frontend_type>
32
+ <source_model>Mage_Adminhtml_Model_System_Config_Source_Yesno</source_model>
33
+ <sort_order>10</sort_order>
34
+ <show_in_default>1</show_in_default>
35
+ <show_in_website>1</show_in_website>
36
+ <show_in_store>1</show_in_store>
37
+ </enabled>
38
+ </fields>
39
+ </options>
40
+ </groups>
41
+ </c3_configsetuphelper>
42
+ </sections>
43
+ </config>
app/etc/modules/C3_ConfigSetupHelper.xml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <C3_ConfigSetupHelper>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ <depends></depends>
8
+ </C3_ConfigSetupHelper>
9
+ </modules>
10
+ </config>
app/locale/en_US/C3_ConfigSetupHelper.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ "Config Setup Helper","Config Setup Helper"
2
+ "Config for","Config for"
3
+ "Settings for %s group","Settings for %s group"
package.xml ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>C3_ConfigSetupHelper</name>
4
+ <version>1.0.1</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.opensource.org/licenses/gpl-license.php">GNU General Public License</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Automatically creates a setup script for selected options in system configuration page.</summary>
10
+ <description>&lt;p&gt;When enabled, adds check-boxes next to each entry in the system config view. By checking some of these, even across multiple groups (though just within one tab), after saving the settings you are presented with the complete code to set these options via a setup script including startSetup and endSetup.&lt;/p&gt;&#xD;
11
+ &#xD;
12
+ &lt;p&gt;Features:&#xD;
13
+ &lt;ul&gt;&lt;li&gt;Speed up development - ready to copy and paste into a setup script and save&lt;/li&gt;&#xD;
14
+ &lt;li&gt;Works with any extension that displays options in the system config&lt;/li&gt;&#xD;
15
+ &lt;li&gt;Self-commenting: Gives section and group names to aid visibility&lt;/li&gt;&lt;/ul&gt;&lt;/p&gt;</description>
16
+ <notes>&lt;p&gt;Features:&#xD;
17
+ &lt;ul&gt;&lt;li&gt;Speed up development - ready to copy and paste into a setup script and save&lt;/li&gt;&#xD;
18
+ &lt;li&gt;Works with any extension that displays options in the system config&lt;/li&gt;&#xD;
19
+ &lt;li&gt;Self-commenting: Gives section and group names to aid visibility&lt;/li&gt;&lt;/ul&gt;&lt;/p&gt;&#xD;
20
+ &#xD;
21
+ &lt;p&gt;Known issues:&#xD;
22
+ &lt;ul&gt;&lt;li&gt;There are some settings in e.g. Paypal that aren&#x2019;t currently outputting correctly. We are looking into this for the next version.&lt;/li&gt;&#xD;
23
+ &lt;li&gt;Oldest supported CE version is 1.7.0.1&lt;/li&gt;&#xD;
24
+ &lt;/ul&gt;</notes>
25
+ <authors><author><name>C3 Media</name><user>c3media_ltd</user><email>hello@c3media.co.uk</email></author></authors>
26
+ <date>2014-08-22</date>
27
+ <time>14:06:08</time>
28
+ <contents><target name="magelocal"><dir name="C3"><dir name="ConfigSetupHelper"><dir name="Block"><dir name="System"><dir name="Config"><dir name="Form"><file name="Field.php" hash="75498e2964682d612f819d6fc1003ce7"/></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="19117a4729fcf4c89a017ff19061fddc"/></dir><dir name="Model"><file name="Observer.php" hash="dbb236e8a403c46b2806a4215ab2d47d"/></dir><dir name="etc"><file name="adminhtml.xml" hash="264455adf68a82fdf90e66bcd8e55311"/><file name="config.xml" hash="6add7801116c1ae661acd4a40b0483bb"/><file name="system.xml" hash="389118cb235a221cdec8ecfcbacc9ac7"/></dir></dir></dir></target><target name="magelocale"><dir name="en_US"><file name="C3_ConfigSetupHelper.csv" hash="d9af8dbceefcb3641627229ee485e891"/></dir></target><target name="mageetc"><dir name="modules"><file name="C3_ConfigSetupHelper.xml" hash="992c432cd6c0d4d87cff46a52f1b19ea"/></dir></target></contents>
29
+ <compatible/>
30
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
31
+ </package>