Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
ISSUE#2 Fix deleting selectors when module disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
xpoback committed Aug 2, 2020
1 parent d3bda5d commit 1ec8b49
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
26 changes: 26 additions & 0 deletions src/Model/Config/Backend/Serialized/ArraySerialized.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* @author Oleh Kravets <[email protected]>
* @copyright Copyright (c) 2020 schoene neue kinder GmbH (https://www.snk.de)
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

namespace Snk\Usercentrics\Model\Config\Backend\Serialized;

class ArraySerialized extends \Magento\Config\Model\Config\Backend\Serialized\ArraySerialized
{
/**
* Skip saving data if the module is not enabled
*
* @return ArraySerialized
*/
public function beforeSave()
{
if (!$this->getFieldsetDataValue('enable')) {
$this->setData('value', $this->getOldValue());

return $this;
}
return parent::beforeSave();
}
}
7 changes: 5 additions & 2 deletions src/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@
<field id="selectors" translate="label" type="select" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Selectors</label>
<frontend_model>Snk\Usercentrics\Block\Adminhtml\System\Config\Form\Field\Selectors</frontend_model>
<backend_model>Magento\Config\Model\Config\Backend\Serialized\ArraySerialized</backend_model>
<backend_model>Snk\Usercentrics\Model\Config\Backend\Serialized\ArraySerialized</backend_model>
<depends><field id="enable">1</field></depends>
<comment><![CDATA[Selectors for html being processed. For more details see <a href="#">documentation</a>.]]></comment>
<comment><![CDATA[Selectors for html being processed. For more details see <a target="_blank"
href="https://github.com/kirchbergerknorr/magento2-module-usercentrics#configuration-details">
documentation on GitHub</a>.]]>
</comment>
</field>
</group>
</section>
Expand Down

0 comments on commit 1ec8b49

Please sign in to comment.