Skip to content

Commit 8dc49d2

Browse files
committed
MAGE-986 Add backend model
1 parent 13e103e commit 8dc49d2

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

Block/Adminhtml/System/Config/Form/Field/Checkboxes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ protected function _getElementHtml(AbstractElement $element)
1313
$elementId = $element->getHtmlId();
1414
$name = $element->getName();
1515
$options = $element->getValues();
16-
$values = $element->getValue() ? explode(',', $element->getValue()) : []; // store as CSV in config
16+
$values = empty($element->getValue()) ? [] : explode(',', $element->getValue()); // store as CSV in config
1717

1818
foreach ($options as $option) {
1919
$value = $option['value'];

Model/Backend/Checkboxes.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Algolia\AlgoliaSearch\Model\Backend;
4+
5+
class Checkboxes extends \Magento\Framework\App\Config\Value
6+
{
7+
public function beforeSave()
8+
{
9+
$value = $this->getValue();
10+
if (is_array($value)) {
11+
$this->setValue(implode(',', $value));
12+
}
13+
return parent::beforeSave();
14+
}
15+
}

Model/Source/InstantSearchRedirectOptions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function toOptionArray()
1717
return [
1818
[
1919
'value' => self::REDIRECT_ON_PAGE_LOAD,
20-
'label' => __('Redirect on page load (if InstantSearch loads with a redirect, immediately take the user to that URL.)'),
20+
'label' => __('Redirect on page load (if InstantSearch loads with a redirect, immediately take the user to that URL)'),
2121
],
2222
[
2323
'value' => self::REDIRECT_ON_SEARCH_AS_YOU_TYPE,

etc/adminhtml/system.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@
570570
<field id="options" translate="label comment" type="select" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
571571
<label>Redirect options</label>
572572
<frontend_model>Algolia\AlgoliaSearch\Block\Adminhtml\System\Config\Form\Field\Checkboxes</frontend_model>
573+
<backend_model>Algolia\AlgoliaSearch\Model\Backend\Checkboxes</backend_model>
573574
<source_model>Algolia\AlgoliaSearch\Model\Source\InstantSearchRedirectOptions</source_model>
574575
<depends><field id="enable">1</field></depends>
575576
</field>

0 commit comments

Comments
 (0)