Countries.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Braintree\Block\Adminhtml\Form\Field;
  7. use Magento\Braintree\Helper\Country;
  8. use Magento\Framework\View\Element\Context;
  9. use Magento\Framework\View\Element\Html\Select;
  10. /**
  11. * Class Countries
  12. */
  13. class Countries extends Select
  14. {
  15. /**
  16. * @var Country
  17. */
  18. private $countryHelper;
  19. /**
  20. * Constructor
  21. *
  22. * @param Context $context
  23. * @param Country $countryHelper
  24. * @param array $data
  25. */
  26. public function __construct(Context $context, Country $countryHelper, array $data = [])
  27. {
  28. parent::__construct($context, $data);
  29. $this->countryHelper = $countryHelper;
  30. }
  31. /**
  32. * Render block HTML
  33. *
  34. * @return string
  35. */
  36. protected function _toHtml()
  37. {
  38. if (!$this->getOptions()) {
  39. $this->setOptions($this->countryHelper->getCountries());
  40. }
  41. return parent::_toHtml();
  42. }
  43. /**
  44. * Sets name for input element
  45. *
  46. * @param string $value
  47. * @return $this
  48. */
  49. public function setInputName($value)
  50. {
  51. return $this->setName($value);
  52. }
  53. }