Skip to content
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

Tiny improvement on render() method in Magento\Backend\Block\Widget\Grid\Column\Ren... #667

Closed
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,15 @@ class Concat extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\Abstract
*/
public function render(\Magento\Framework\Object $row)
{
$dataArr = array();
foreach ($this->getColumn()->getIndex() as $index) {
if ($data = $row->getData($index)) {
$dataArr = [];
$methods = $this->getColumn()->getGetter() ? $this->getColumn()->getGetter() : $this->getColumn()->getIndex();
Copy link
Contributor

Choose a reason for hiding this comment

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

it will more readable as

    $column = $this->getColumn();
    $methods = $column->getGetter() ?: $column->getIndex();

foreach ($methods as $m) {
if (true === is_callable([$row, $m])) {
Copy link
Contributor

Choose a reason for hiding this comment

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

is_callable always return true for class with __call method

Copy link
Member Author

Choose a reason for hiding this comment

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

Crap PHP :-(
Indeed. Must use method_exists.
Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

method_exists is also not suitable, because it's cannot get data over magic getters
moreover, better to check that method starts from get to call only getters

$data = call_user_func(array($row, $m), $this->getColumn());
Copy link
Contributor

Choose a reason for hiding this comment

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

Magic setters in Magento Object expects the first parameter will be array keys compatible type.
Test shows it very well 😉

} else {
$data = $row->getData($m);
}
if (false === empty($data)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe that !empty() is more understandable

$dataArr[] = $data;
}
}
Expand Down