Skip to content

Small refactoring to better code readability #16010

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

Merged
merged 2 commits into from
Jun 14, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions app/code/Magento/Backend/Block/Widget/Form/Element/Dependence.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,17 @@ protected function _toHtml()
if (!$this->_depends) {
return '';
}
return '<script>
require(["mage/adminhtml/form"], function(){
new FormElementDependenceController(' .
$this->_getDependsJson() .
($this->_configOptions ? ', ' .
$this->_jsonEncoder->encode(
$this->_configOptions
) : '') . '); });</script>';

$dependsJson = $this->_getDependsJson();
$configOptions = $this->_configOptions ? $this->_jsonEncoder->encode($this->_configOptions) : null;
$configOptionsStr = $configOptions ? ', ' . $configOptions : '';
$paramsStr = $dependsJson . $configOptionsStr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO readability could be slightly improved if you do like this:

$params = $this->_getDependsJson();
if ($this->_configOptions) {
    $params .= ', ' . $this->_configOptions;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@orlangur, Absolutely agree with you. I updated pull request according to your suggestion.


return "<script>
require(['mage/adminhtml/form'], function(){
new FormElementDependenceController({$paramsStr});
});
</script>";
}

/**
Expand Down