Skip to content

Commit

Permalink
add the block for create webhook button #229
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzaloebiz committed Mar 12, 2018
1 parent 5587166 commit 866a9f8
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions Block/Adminhtml/System/Config/CreateWebhook.php
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);
}
}

0 comments on commit 866a9f8

Please sign in to comment.