Skip to content

[Config] Giving the possibility to have a config dependency based on empty config value #25774

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

Conversation

eduard13
Copy link
Contributor

Description (*)

This PR provides a way to set a dependency to a field based on the empty value.

For example:
You have 2 input config fields, and you want to hide the 2nd one if the 1st one won't be empty.

2019-11-27 15 25 13

Our system.xml will look like:

<field id="first_input" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
    <label>First Input</label>
</field>
<field id="second_input" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
    <label>Second input</label>
    <comment><![CDATA[Dependent by 1st field]]></comment>
    <depends>
        <field id="*/*/first_input"/>
    </depends>
</field>

Fixed Issues (if relevant)

N/A

Manual testing scenarios (*)

  1. Add to any system config group the provided sample code
  2. Open it in the admin panel
  3. Type something in the 1st input
  4. The second should be hidden

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

@eduard13 eduard13 requested a review from paliarush as a code owner November 27, 2019 13:34
@m2-assistant
Copy link

m2-assistant bot commented Nov 27, 2019

Hi @eduard13. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.3-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Guide documentation.

@magento-engcom-team magento-engcom-team added Component: Config Release Line: 2.3 Partner: Atwix Pull Request is created by partner Atwix partners-contribution Pull Request is created by Magento Partner labels Nov 27, 2019
@eduard13
Copy link
Contributor Author

Based on the Backward Compatibility Policy, we shouldn't change classes marked as @api, but what do you @paliarush think about having a such feature?
Thank you.

@dmytro-ch dmytro-ch self-assigned this Nov 28, 2019
Copy link
Contributor

@dmytro-ch dmytro-ch left a comment

Choose a reason for hiding this comment

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

Hi @eduard13,
great job, thank you!

Based on the Backward Compatibility Policy, we shouldn't change classes marked as @api

No, it's not relevant unless we change the signature of public/protected methods or introduce new properties or methods, etc.

The only thing, I guess, the behavior you mentioned in description should apear in case the negative="1" attribute is set.
e.g. with the following configuration:

<depends>
    <field id="*/*/first_input" negative="1"/>
</depends>

the second field should be shown if the first one is empty, and vice versa.
Feel free to contact me for further discussion if necessary, or correct me if I'm wrong.

Could you please also implement the recommendations from the static test report?

Thank you!

@eduard13
Copy link
Contributor Author

eduard13 commented Dec 3, 2019

Hi @dmytro-ch, thank you for your review. Actually not sure what negative does, but we can't have an empty value for our dependency. We'll get Notice: Undefined index: value in /home/dev/sites/mage23/app/code/Magento/Config/Model/Config/Structure/Element/Dependency/Field.php on line 44.
Basically the provided change fixes this warning and gives us the possibility to set a dependency on empty value.
Please let me know your thoughts on this matter.

Thank you.

@dmytro-ch dmytro-ch added Award: test coverage Auto-Tests: Covered All changes in Pull Request is covered by auto-tests labels Dec 4, 2019
@dmytro-ch
Copy link
Contributor

After taking a closer look at the issue and having an additional discussion, we decided to proceed with the current behaviour to keep the logic of \Magento\Config\Model\Config\Structure\Element\Dependency\Field as straightforward as possible.

@magento-engcom-team
Copy link
Contributor

Hi @dmytro-ch, thank you for the review.
ENGCOM-6390 has been created to process this Pull Request

@engcom-Alfa
Copy link
Contributor

✔️ QA Passed

Before:
[2019-12-04 10:05:40] main.CRITICAL: Notice: Undefined index: value in /home/arthur/sites/magento/magento23/app/code/Magento/Config/Model/Config/Structure/Element/Dependency/Field.php on line 44 [] []

After:
after

@sidolov sidolov changed the base branch from 2.3-develop to 2.4-develop December 5, 2019 17:12
magento-engcom-team pushed a commit that referenced this pull request Dec 8, 2019
@magento-engcom-team magento-engcom-team merged commit 37fc4e5 into magento:2.4-develop Dec 8, 2019
@m2-assistant
Copy link

m2-assistant bot commented Dec 8, 2019

Hi @eduard13, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Award: bug fix Award: test coverage Component: Config Partner: Atwix Pull Request is created by partner Atwix partners-contribution Pull Request is created by Magento Partner Progress: accept Release Line: 2.4
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants