Country.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * @copyright Vertex. All rights reserved. https://www.vertexinc.com/
  4. * @author Mediotype https://www.mediotype.com/
  5. */
  6. namespace Vertex\Tax\Model\Config\Source;
  7. use Magento\Framework\Data\OptionSourceInterface;
  8. use Vertex\Tax\Model\ResourceModel\Country\Collection;
  9. /**
  10. * Frontend source model for country select drop down
  11. */
  12. class Country implements OptionSourceInterface
  13. {
  14. /** @var Collection */
  15. private $countryCollection;
  16. /** @var array */
  17. private $options;
  18. /**
  19. * @param Collection $countryCollection
  20. */
  21. public function __construct(Collection $countryCollection)
  22. {
  23. $this->countryCollection = $countryCollection;
  24. }
  25. /**
  26. * Return options array
  27. *
  28. * @return array
  29. */
  30. public function toOptionArray()
  31. {
  32. if (!$this->options) {
  33. $this->options = $this->countryCollection->toOptionArrayISO3();
  34. array_unshift($this->options, ['value' => '', 'label' => __('--Please Select--')]);
  35. }
  36. return $this->options;
  37. }
  38. }