This repository has been archived by the owner on Jul 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
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
Showing
16 changed files
with
554 additions
and
177 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,31 @@ | ||
<?php | ||
|
||
namespace Meanbee\ServiceWorker\Block\Adminhtml\Form\Field; | ||
|
||
use \Magento\Framework\View\Element; | ||
|
||
class CachingStrategy extends Element\Html\Select | ||
{ | ||
|
||
public function __construct( | ||
Element\Context $context, | ||
\Meanbee\ServiceWorker\Model\Config\Source\CachingStrategy $optionsProvider, | ||
array $data = [] | ||
) { | ||
parent::__construct($context, $data); | ||
|
||
$this->setOptions($optionsProvider->toOptionArray()); | ||
} | ||
|
||
/** | ||
* Set the input element name. | ||
* | ||
* @param string $name | ||
* | ||
* @return $this | ||
*/ | ||
public function setInputName($name) | ||
{ | ||
return $this->setName($name); | ||
} | ||
} |
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 @@ | ||
<?php | ||
|
||
namespace Meanbee\ServiceWorker\Block\Adminhtml\Form\Field; | ||
|
||
class CustomStrategies extends \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray | ||
{ | ||
/** @var CachingStrategy */ | ||
protected $strategyRenderer; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function _prepareToRender() | ||
{ | ||
$this->addColumn("path", [ | ||
"label" => __("URL Path"), | ||
]); | ||
|
||
$this->addColumn("strategy", [ | ||
"label" => __("Strategy"), | ||
"renderer" => $this->getStrategyRenderer(), | ||
]); | ||
|
||
$this->_addAfter = false; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function _prepareArrayRow(\Magento\Framework\DataObject $row) | ||
{ | ||
$optionName = sprintf("option_%s", $this->getStrategyRenderer()->calcOptionHash($row->getData("strategy"))); | ||
|
||
$row->setData("option_extra_attrs", [ | ||
$optionName => 'selected="selected"', | ||
]); | ||
} | ||
|
||
/** | ||
* Get the caching strategy input field renderer. | ||
* | ||
* @return CachingStrategy | ||
*/ | ||
protected function getStrategyRenderer() | ||
{ | ||
if (!$this->strategyRenderer) { | ||
$this->strategyRenderer = $this->getLayout()->createBlock( | ||
CachingStrategy::class, | ||
"", | ||
["data" => [ | ||
"is_render_to_js_template" => true, | ||
]] | ||
); | ||
} | ||
|
||
return $this->strategyRenderer; | ||
} | ||
} |
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
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
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,41 @@ | ||
<?php | ||
|
||
namespace Meanbee\ServiceWorker\Model\Config\Source; | ||
|
||
class CachingStrategy implements \Magento\Framework\Option\ArrayInterface | ||
{ | ||
const CACHE_FIRST = "cacheFirst"; | ||
const NETWORK_FIRST = "networkFirst"; | ||
const NETWORK_ONLY = "networkOnly"; | ||
|
||
/** | ||
* Get options in "key-value" format | ||
* | ||
* @return string[] | ||
*/ | ||
public function toArray() | ||
{ | ||
return [ | ||
static::CACHE_FIRST => __("Cache First"), | ||
static::NETWORK_FIRST => __("Network First"), | ||
static::NETWORK_ONLY => __("Network Only"), | ||
]; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function toOptionArray() | ||
{ | ||
$options = $this->toArray(); | ||
|
||
array_walk($options, function (&$value, $key) { | ||
$value = [ | ||
"value" => $key, | ||
"label" => $value, | ||
]; | ||
}); | ||
|
||
return $options; | ||
} | ||
} |
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
Oops, something went wrong.