Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Options.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Customer\Model;
7 
9 use Magento\Customer\Helper\Address as AddressHelper;
11 
12 class Options
13 {
19  protected $addressHelper;
20 
24  protected $escaper;
25 
30  public function __construct(
31  AddressHelper $addressHelper,
33  ) {
34  $this->addressHelper = $addressHelper;
35  $this->escaper = $escaper;
36  }
37 
44  public function getNamePrefixOptions($store = null)
45  {
46  return $this->prepareNamePrefixSuffixOptions(
47  $this->addressHelper->getConfig('prefix_options', $store),
48  $this->addressHelper->getConfig('prefix_show', $store) == NooptreqSource::VALUE_OPTIONAL
49  );
50  }
51 
58  public function getNameSuffixOptions($store = null)
59  {
60  return $this->prepareNamePrefixSuffixOptions(
61  $this->addressHelper->getConfig('suffix_options', $store),
62  $this->addressHelper->getConfig('suffix_show', $store) == NooptreqSource::VALUE_OPTIONAL
63  );
64  }
65 
74  protected function _prepareNamePrefixSuffixOptions($options, $isOptional = false)
75  {
76  return $this->prepareNamePrefixSuffixOptions($options, $isOptional);
77  }
78 
87  private function prepareNamePrefixSuffixOptions($options, $isOptional = false)
88  {
89  $options = trim($options);
90  if (empty($options)) {
91  return false;
92  }
93  $result = [];
94  $options = explode(';', $options);
95  foreach ($options as $value) {
96  $value = $this->escaper->escapeHtml(trim($value));
98  }
99  if ($isOptional && trim(current($options))) {
100  $result = array_merge([' ' => ' '], $result);
101  }
102 
103  return $result;
104  }
105 }
getNamePrefixOptions($store=null)
Definition: Options.php:44
$value
Definition: gender.phtml:16
__construct(AddressHelper $addressHelper, Escaper $escaper)
Definition: Options.php:30
getNameSuffixOptions($store=null)
Definition: Options.php:58
_prepareNamePrefixSuffixOptions($options, $isOptional=false)
Definition: Options.php:74