-
Notifications
You must be signed in to change notification settings - Fork 9.4k
#7241: Always add empty option for prefix and/or suffix if optional #11462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
11e38f6
7800e5d
252529f
519b805
eb79b38
fce3afe
3e38118
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
*/ | ||
namespace Magento\Customer\Model; | ||
|
||
use Magento\Config\Model\Config\Source\Nooptreq as NooptreqSource; | ||
use Magento\Customer\Helper\Address as AddressHelper; | ||
use Magento\Framework\Escaper; | ||
|
||
|
@@ -42,7 +43,10 @@ public function __construct( | |
*/ | ||
public function getNamePrefixOptions($store = null) | ||
{ | ||
return $this->_prepareNamePrefixSuffixOptions($this->addressHelper->getConfig('prefix_options', $store)); | ||
return $this->prepareNamePrefixSuffixOptions( | ||
$this->addressHelper->getConfig('prefix_options', $store), | ||
$this->addressHelper->getConfig('prefix_show', $store) == NooptreqSource::VALUE_OPTIONAL | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately we will need to change this since we cannot add the new constants. |
||
); | ||
} | ||
|
||
/** | ||
|
@@ -53,16 +57,34 @@ public function getNamePrefixOptions($store = null) | |
*/ | ||
public function getNameSuffixOptions($store = null) | ||
{ | ||
return $this->_prepareNamePrefixSuffixOptions($this->addressHelper->getConfig('suffix_options', $store)); | ||
return $this->prepareNamePrefixSuffixOptions( | ||
$this->addressHelper->getConfig('suffix_options', $store), | ||
$this->addressHelper->getConfig('suffix_show', $store) == NooptreqSource::VALUE_OPTIONAL | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately we will need to change this since we cannot add the new constants. |
||
); | ||
} | ||
|
||
/** | ||
* @param $options | ||
* @param bool $isOptional | ||
* @return array|bool | ||
* | ||
* @deprecated | ||
* @see prepareNamePrefixSuffixOptions() | ||
*/ | ||
protected function _prepareNamePrefixSuffixOptions($options, $isOptional = false) | ||
{ | ||
return $this->prepareNamePrefixSuffixOptions($options, $isOptional); | ||
} | ||
|
||
/** | ||
* Unserialize and clear name prefix or suffix options | ||
* If field is optional, add an empty first option. | ||
* | ||
* @param string $options | ||
* @param bool $isOptional | ||
* @return array|bool | ||
*/ | ||
protected function _prepareNamePrefixSuffixOptions($options) | ||
private function prepareNamePrefixSuffixOptions($options, $isOptional = false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As part of the BC guidelines you cannot remove a protected method http://devdocs.magento.com/guides/v2.2/contributor-guide/backward-compatible-development/#public-and-protected-method-removal I would suggest that you keep the private method and the internal calls to this private method and then simply add back the protected method that simply calls the private method and mark it as deprecated. |
||
{ | ||
$options = trim($options); | ||
if (empty($options)) { | ||
|
@@ -74,6 +96,10 @@ protected function _prepareNamePrefixSuffixOptions($options) | |
$value = $this->escaper->escapeHtml(trim($value)); | ||
$result[$value] = $value; | ||
} | ||
if ($isOptional && trim(current($options))) { | ||
$result = array_merge([' ' => ' '], $result); | ||
} | ||
|
||
return $result; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly while putting this to the
2.2-develop
branch and with this class marked as@api
we cannot add any new constants. For a PR to2.3-develop
we could add these new constants. For this PR we will have to change this back.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why adding new constants is an issue? It doesn't affect backwards compatibility and only improves things, I don't see any disadavantage of that... sounds like a quite arbitrary rule to me, but perhaps it gets clearer if you explain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @dmanners in general, you are right. But in this particular, we can accept new constants. There are some cases when new constants can break client code, but the chances a very low.
@dmanners @avstudnitz thank you for collaboration