TestConnection.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\AdvancedSearch\Block\Adminhtml\System\Config;
  7. /**
  8. * Search engine test connection block
  9. * @api
  10. * @since 100.1.0
  11. */
  12. class TestConnection extends \Magento\Config\Block\System\Config\Form\Field
  13. {
  14. /**
  15. * Set template to itself
  16. *
  17. * @return $this
  18. * @since 100.1.0
  19. */
  20. protected function _prepareLayout()
  21. {
  22. parent::_prepareLayout();
  23. $this->setTemplate('Magento_AdvancedSearch::system/config/testconnection.phtml');
  24. return $this;
  25. }
  26. /**
  27. * Unset some non-related element parameters
  28. *
  29. * @param \Magento\Framework\Data\Form\Element\AbstractElement $element
  30. * @return string
  31. * @since 100.1.0
  32. */
  33. public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
  34. {
  35. $element = clone $element;
  36. $element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
  37. return parent::render($element);
  38. }
  39. /**
  40. * Get the button and scripts contents
  41. *
  42. * @param \Magento\Framework\Data\Form\Element\AbstractElement $element
  43. * @return string
  44. * @since 100.1.0
  45. */
  46. protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
  47. {
  48. $originalData = $element->getOriginalData();
  49. $this->addData(
  50. [
  51. 'button_label' => __($originalData['button_label']),
  52. 'html_id' => $element->getHtmlId(),
  53. 'ajax_url' => $this->_urlBuilder->getUrl('catalog/search_system_config/testconnection'),
  54. 'field_mapping' => str_replace('"', '\\"', json_encode($this->_getFieldMapping()))
  55. ]
  56. );
  57. return $this->_toHtml();
  58. }
  59. /**
  60. * Returns configuration fields required to perform the ping request
  61. *
  62. * @return array
  63. * @since 100.1.0
  64. */
  65. protected function _getFieldMapping()
  66. {
  67. return ['engine' => 'catalog_search_engine'];
  68. }
  69. }