/** * Forms script response * * @return string */ public function _toHtml() { $updateResult = $this->_coreRegistry->registry('composite_update_result'); $resultJson = $this->_jsonEncoder->encode($updateResult); $jsVarname = $updateResult->getJsVarName(); return $this->_jsHelper->getScript(sprintf('var %s = %s', $jsVarname, $resultJson)); }
/** * Render block HTML * * @return string */ protected function _toHtml() { $result = []; $layout = $this->getLayout(); foreach ($this->getChildNames() as $name) { $result[$name] = $layout->renderElement($name); } $resultJson = $this->_jsonEncoder->encode($result); $jsVarname = $this->getRequest()->getParam('as_js_varname'); if ($jsVarname) { return $this->_jsHelper->getScript(sprintf('var %s = %s', $jsVarname, $resultJson)); } else { return $resultJson; } }
/** * Render fieldset html * * @param \Magento\Framework\Data\Form\Element\AbstractElement $element * @return string */ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element) { $elementOriginalData = $element->getOriginalData(); if (isset($elementOriginalData['help_link'])) { $this->setHelpLink($elementOriginalData['help_link']); } $js = ' paypalToggleSolution = function(id, url) { var doScroll = false; Fieldset.toggleCollapse(id, url); if ($(this).hasClassName("open")) { $$(".with-button button.button").each(function(anotherButton) { if (anotherButton != this && $(anotherButton).hasClassName("open")) { $(anotherButton).click(); doScroll = true; } }.bind(this)); } if (doScroll) { var pos = Element.cumulativeOffset($(this)); window.scrollTo(pos[0], pos[1] - 45); } } togglePaypalSolutionConfigureButton = function(button, enable) { var $button = $(button); $button.disabled = !enable; if ($button.hasClassName("disabled") && enable) { $button.removeClassName("disabled"); } else if (!$button.hasClassName("disabled") && !enable) { $button.addClassName("disabled"); } } // check store-view disabling Express Checkout document.observe("dom:loaded", function() { $$(".pp-method-express button.button").each(function(ecButton){ var ecEnabler = $$(".paypal-ec-enabler")[0]; if (typeof ecButton == "undefined" || typeof ecEnabler != "undefined") { return; } var $ecButton = $(ecButton); $$(".with-button button.button").each(function(configureButton) { if (configureButton != ecButton && !configureButton.disabled && !$(configureButton).hasClassName("paypal-ec-separate") ) { togglePaypalSolutionConfigureButton(ecButton, false); } }); }); }); '; return $this->toHtml() . $this->_jsHelper->getScript($js); }
/** * @param null|string $requestCountry * @param null|string $requestDefaultCountry * @param bool $canUseDefault * @param bool $inherit * @dataProvider renderDataProvider */ public function testRender($requestCountry, $requestDefaultCountry, $canUseDefault, $inherit) { $this->_request->expects($this->any())->method('getParam')->will($this->returnCallback(function ($param) use($requestCountry, $requestDefaultCountry) { if ($param == \Magento\Paypal\Model\Config\StructurePlugin::REQUEST_PARAM_COUNTRY) { return $requestCountry; } if ($param == Country::REQUEST_PARAM_DEFAULT_COUNTRY) { return $requestDefaultCountry; } return $param; })); $this->_element->setInherit($inherit); $this->_element->setCanUseDefaultValue($canUseDefault); $constraints = [new \PHPUnit_Framework_Constraint_StringContains('document.observe("dom:loaded", function() {'), new \PHPUnit_Framework_Constraint_StringContains('$("' . $this->_element->getHtmlId() . '").observe("change", function () {')]; if ($canUseDefault && $requestCountry == 'US' && $requestDefaultCountry) { $constraints[] = new \PHPUnit_Framework_Constraint_StringContains('$("' . $this->_element->getHtmlId() . '_inherit").observe("click", function () {'); } $this->_jsHelper->expects($this->once())->method('getScript')->with(new \PHPUnit_Framework_Constraint_And($constraints)); $this->_url->expects($this->once())->method('getUrl')->with('*/*/*', ['section' => 'section', 'website' => 'website', 'store' => 'store', \Magento\Paypal\Model\Config\StructurePlugin::REQUEST_PARAM_COUNTRY => '__country__']); $this->_model->render($this->_element); }
/** * Get country selector html * * @param \Magento\Framework\Data\Form\Element\AbstractElement $element * @return string */ protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element) { $urlParams = ['section' => $this->getRequest()->getParam('section'), 'website' => $this->getRequest()->getParam('website'), 'store' => $this->getRequest()->getParam('store'), StructurePlugin::REQUEST_PARAM_COUNTRY => '__country__']; $urlString = $this->_escaper->escapeJsQuote($this->_url->getUrl('*/*/*', $urlParams)); $jsString = ' $("' . $element->getHtmlId() . '").observe("change", function () { location.href = \'' . $urlString . '\'.replace("__country__", this.value); }); '; if ($this->_defaultCountry) { $urlParams[self::REQUEST_PARAM_DEFAULT_COUNTRY] = '__default__'; $urlString = $this->_escaper->escapeJsQuote($this->_url->getUrl('*/*/*', $urlParams)); $jsParentCountry = $this->_escaper->escapeJsQuote($this->_defaultCountry); $jsString .= ' $("' . $element->getHtmlId() . '_inherit").observe("click", function () { if (this.checked) { location.href = \'' . $urlString . '\'.replace("__country__", \'' . $jsParentCountry . '\') .replace("__default__", "1"); } }); '; } return parent::_getElementHtml($element) . $this->_jsHelper->getScript('require([\'prototype\'], function(){document.observe("dom:loaded", function() {' . $jsString . '});});'); }
/** * Return js code for fieldset: * - observe fieldset rows; * - apply collapse; * * @param AbstractElement $element * @return string */ protected function _getExtraJs($element) { $htmlId = $element->getHtmlId(); $output = "require(['prototype'], function(){Fieldset.applyCollapse('{$htmlId}');});"; return $this->_jsHelper->getScript($output); }