ApiWizard.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Block\Adminhtml\System\Config;
  7. /**
  8. * Custom renderer for PayPal API credentials wizard popup
  9. */
  10. class ApiWizard extends \Magento\Config\Block\System\Config\Form\Field
  11. {
  12. /**
  13. * Path to block template
  14. */
  15. const WIZARD_TEMPLATE = 'Magento_Paypal::system/config/api_wizard.phtml';
  16. /**
  17. * Set template to itself
  18. *
  19. * @return $this
  20. */
  21. protected function _prepareLayout()
  22. {
  23. parent::_prepareLayout();
  24. if (!$this->getTemplate()) {
  25. $this->setTemplate(static::WIZARD_TEMPLATE);
  26. }
  27. return $this;
  28. }
  29. /**
  30. * Unset some non-related element parameters
  31. *
  32. * @param \Magento\Framework\Data\Form\Element\AbstractElement $element
  33. * @return string
  34. */
  35. public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
  36. {
  37. $element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
  38. return parent::render($element);
  39. }
  40. /**
  41. * Get the button and scripts contents
  42. *
  43. * @param \Magento\Framework\Data\Form\Element\AbstractElement $element
  44. * @return string
  45. */
  46. protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
  47. {
  48. $originalData = $element->getOriginalData();
  49. $this->addData(
  50. [
  51. // Global
  52. 'query' => $this->createQuery(
  53. [
  54. 'partnerId' => $originalData['partner_id'],
  55. 'partnerLogoUrl' => $this->_assetRepo->getUrl($originalData['partner_logo_url']),
  56. 'receiveCredentials' => $originalData['receive_credentials'],
  57. 'showPermissions' => $originalData['show_permissions'],
  58. 'displayMode' => $originalData['display_mode'],
  59. 'productIntentID' => $originalData['product_intent_id'],
  60. ]
  61. ),
  62. // Live
  63. 'button_label' => __($originalData['button_label']),
  64. 'button_url' => $originalData['button_url'],
  65. 'html_id' => $element->getHtmlId(),
  66. // Sandbox
  67. 'sandbox_button_label' => __($originalData['sandbox_button_label']),
  68. 'sandbox_button_url' => $originalData['sandbox_button_url'],
  69. 'sandbox_html_id' => 'sandbox_' . $element->getHtmlId(),
  70. ]
  71. );
  72. return $this->_toHtml();
  73. }
  74. /**
  75. * Create request query
  76. *
  77. * @param array $requestData
  78. * @return string
  79. */
  80. private function createQuery(array $requestData)
  81. {
  82. $query = [];
  83. foreach ($requestData as $name => $value) {
  84. $query[] = sprintf('%s=%s', $name, $value);
  85. }
  86. return implode('&', $query);
  87. }
  88. }