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

Fix Inconsistency #2448

Merged
merged 4 commits into from
Mar 23, 2017
Merged

Fix Inconsistency #2448

merged 4 commits into from
Mar 23, 2017

Conversation

srenon
Copy link
Member

@srenon srenon commented Nov 20, 2015

Fix Inconsistency between $this->buttonList->add(...) and $this->addButton(...).

See /app/code/Magento/Backend/Block/Widget/Container.php

   public function addButton($buttonId, $data, $level = 0, $sortOrder = 0, $region = 'toolbar')
    {
        $this->buttonList->add($buttonId, $data, $level, $sortOrder, $region);
        return $this;
    }

Fix Inconsistency between $this->buttonList->add(...) and $this->addButton(...).

See /app/code/Magento/Backend/Block/Widget/Container.php

   public function addButton($buttonId, $data, $level = 0, $sortOrder = 0, $region = 'toolbar')
    {
        $this->buttonList->add($buttonId, $data, $level, $sortOrder, $region);
        return $this;
    }
@Vinai
Copy link
Contributor

Vinai commented Nov 25, 2015

How about also replacing $this->buttonList->remove() calls with $this->removeButton()? That would further increase the consistency of the class.

We will have to wait for the travis build infrastructure to be fixed for the tests to pass. Once that happens we will be able to further process your PR.

@Vinai Vinai added the PS label Nov 25, 2015
@srenon
Copy link
Member Author

srenon commented Nov 25, 2015

@Vinai ... Good catch, my main focus at the time was trying to figure out how to add a button in sales order view. See http://magento.stackexchange.com/questions/91071/how-to-add-a-custom-button-to-admin-sales-order-view-in-magento2

@srenon
Copy link
Member Author

srenon commented Nov 25, 2015

@Vinai ... After reviewing Magento\Sales\Block\Adminhtml\Order\View.php

Using $this->buttonList->add/remove seem to be more consistent, because it is use 14 times while $this->addButton was only use 2 times.

But if you take a look at \Magento\Backend\Block\Widget\Form\Container (extended by View ) they are using $this->addButton()

And if you take a look at \Magento\Backend\Block\Widget\Container (extended by Container) this is where addButton() and removeButton() functionality was implemented.

So maybe the solution here is to stop using $this->buttonList which would make this pull request irrelevant.

@Vinai
Copy link
Contributor

Vinai commented Nov 25, 2015

Well, consistency in this case only means doing things in the same way - not which way.
I think using a protected property of a parent class is a lot more risky then using calling protected methods provided by a parent class. Using protected properties is not really better then using global variables. At least it exposes the same risks. It breaks encapsulation.
So if I where writing the Order\View class I'd either depend on my own instance of the button list in my constructor, or I'd only call the parent methods to manipulate the parents button list instance.
But of course for whatever reason (maybe legacy) it's a fact that in Magento protected properties are used by child classes all over the place. So who am I to argue against it.

@srenon
Copy link
Member Author

srenon commented Nov 25, 2015

As i mention before my main focus was trying to add a button to the toolbar and notice this inconsistency without review the parent classes (and maybe we already spending too much time on this).

But after reviewing all the classes, the current way to do this is $this->updateButton(), $this->removeButton(), and $this->addButton() since these are public method and $this->buttonList is protected.

So the question is, do we want to make Order\View consistent, all the files consistent or just leave it alone

@Vinai
Copy link
Contributor

Vinai commented Nov 25, 2015

Leaving code alone makes it worse :)
If you ask me, please update the PR so the parent methods are used. I can't promise it will be accepted (not my call), but I think that would be the right thing to do.

Use parent method instead of protected properties
@vancoz
Copy link

vancoz commented Jan 12, 2016

Hello @srenon, please merge latest from develop and rerun builds.

@srenon srenon closed this Jan 20, 2016
@srenon srenon deleted the patch-1 branch January 20, 2016 19:59
@srenon srenon restored the patch-1 branch January 20, 2016 21:44
@srenon
Copy link
Member Author

srenon commented Jan 20, 2016

I'm reopening this because I accidentally delete the branch

@srenon srenon reopened this Jan 20, 2016
@NadiyaS
Copy link
Contributor

NadiyaS commented May 10, 2016

Hi @srenon ,
thank you for contribution and we are sorry for delay.
Internal ticket MAGETWO-52647 was created to process your PR.

@NadiyaS NadiyaS added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label May 10, 2016
@vkorotun vkorotun added Component: Sales bugfix and removed CS Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development labels Aug 3, 2016
@sshrewz sshrewz added the linked label Aug 11, 2016
@vkorotun vkorotun added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development and removed linked labels Aug 22, 2016
@vrann vrann self-assigned this Mar 22, 2017
@vrann vrann added this to the March 2017 milestone Mar 22, 2017
@magento-team magento-team merged commit 0604459 into magento:develop Mar 23, 2017
magento-team pushed a commit that referenced this pull request Mar 23, 2017
@ishakhsuvarov
Copy link
Contributor

@srenon Thanks for contributing!

@NadiyaS NadiyaS removed their assignment Mar 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Component: Sales Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Progress: accept
Projects
None yet
Development

Successfully merging this pull request may close these issues.