-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add the block for create webhook button #229
- Loading branch information
1 parent
5587166
commit 866a9f8
Showing
1 changed file
with
76 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,76 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: gonzalo | ||
* Date: 3/12/18 | ||
* Time: 2:12 PM | ||
*/ | ||
namespace Ebizmarts\MailChimp\Block\Adminhtml\System\Config; | ||
|
||
class CreateWebhook extends \Magento\Config\Block\System\Config\Form\Field | ||
{ | ||
/** | ||
* @var \Ebizmarts\MailChimp\Helper\Data | ||
*/ | ||
private $_helper; | ||
|
||
/** | ||
* ResetErrors constructor. | ||
* @param \Magento\Backend\Block\Template\Context $context | ||
* @param \Ebizmarts\MailChimp\Helper\Data $helper | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
\Magento\Backend\Block\Template\Context $context, | ||
\Ebizmarts\MailChimp\Helper\Data $helper, | ||
array $data = [] | ||
) { | ||
|
||
$this->_helper = $helper; | ||
parent::__construct($context, $data); | ||
} | ||
|
||
protected function _construct() | ||
{ | ||
parent::_construct(); | ||
$this->setTemplate('system/config/createwebhook.phtml'); | ||
} | ||
|
||
protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element) | ||
{ | ||
$originalData = $element->getOriginalData(); | ||
$this->addData( | ||
[ | ||
'button_label' => __($originalData['button_label']), | ||
'button_url' => $this->getAjaxCheckUrl(), | ||
'html_id' => $element->getHtmlId(), | ||
] | ||
); | ||
return $this->_toHtml(); | ||
} | ||
|
||
public function getButtonHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element) | ||
{ | ||
|
||
|
||
$originalData = $element->getOriginalData(); | ||
$label = $originalData['button_label']; | ||
$this->addData([ | ||
'button_label' => __($label), | ||
'button_url' => $this->getAjaxCreateWebhookUrl(), | ||
'html_id' => $element->getHtmlId(), | ||
]); | ||
return $this->_toHtml(); | ||
} | ||
public function getAjaxCreateWebhookUrl() | ||
{ | ||
$params = $this->getRequest()->getParams(); | ||
$scope = []; | ||
if (isset($params['website'])) { | ||
$scope = ['website'=>$params['website']]; | ||
} elseif (isset($params['store'])) { | ||
$scope = ['store'=>$params['store']]; | ||
} | ||
return $this->_urlBuilder->getUrl('mailchimp/ecommerce/CreateWebhook', $scope); | ||
} | ||
} |