cancel
Showing results for 
Search instead for 
Did you mean: 

YAML configuration files

SOLVED

YAML configuration files

Hello Alan!

 

Thanks for the wonderful cart! I'm considering a switch to Magento 2 from a custom built cart I've written in Laravel. 

 

I do a lot of work in Ansible and love the yaml based configuration files. Wondering if there is ever a possibility that Magento could offer YAML based config files alongside XML. I find the YAML files much cleaner and easer to understand, but I'm sure there's some technical reasons to use XML.

 

here's an example of some code online that I ran through a converter.

 

 

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
        <section id="payment">
            <group id="sample_gateway" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Sample Gateway</label>
                <field id="active" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Enabled</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                </field>
                <field id="title" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Title</label>
                </field>
                <field id="merchant_gateway_key" translate="label" type="obscure" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Merchant Gateway Key</label>
                    <backend_model>Magento\Config\Model\Config\Backend\Encrypted</backend_model>
                </field>
                <field id="debug" translate="label" type="select" sortOrder="85" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Debug</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                </field>
                <field id="payment_action" translate="label" type="select" sortOrder="110" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Payment Action</label>
                    <source_model>Magento\SamplePaymentGateway\Model\Adminhtml\Source\PaymentAction</source_model>
                </field>
                <field id="allowspecific" translate="label" type="allowspecific" sortOrder="130" showInDefault="9"
                       showInWebsite="1" showInStore="0">
                    <label>Payment From Applicable Countries</label>
                    <source_model>Magento\Payment\Model\Config\Source\Allspecificcountries</source_model>
                </field>
                <field id="specificcountry" translate="label" type="multiselect" sortOrder="140" showInDefault="1"
                       showInWebsite="1" showInStore="0">
                    <label>Payment From Specific Countries</label>
                    <source_model>Magento\Directory\Model\Config\Source\Country</source_model>
                </field>
                <field id="sort_order" translate="label" type="text" sortOrder="160" showInDefault="1" showInWebsite="1"
                       showInStore="0">
                    <label>Sort Order</label>
                    <frontend_class>validate-number</frontend_class>
                </field>
            </group>
        </section>
    </system>
</config>





 

vs

 

config: 
 system: 
  section: 
   group: 
    label: "Sample Gateway"
    field: 
     - 
   label: Enabled
      source_model: "Magento\\Config\\Model\\Config\\Source\\Yesno"
      _id: active
      _translate: label
      _type: select
      _sortOrder: 10
      _showInDefault: 1
      _showInWebsite: 1
      _showInStore: 0
     - 
   label: Title
      _id: title
      _translate: label
      _type: text
      _sortOrder: 20
      _showInDefault: 1
      _showInWebsite: 1
      _showInStore: 1
     - 
   label: "Merchant Gateway Key"
      backend_model: "Magento\\Config\\Model\\Config\\Backend\\Encrypted"
      _id: merchant_gateway_key
      _translate: label
      _type: obscure
      _sortOrder: 30
      _showInDefault: 1
      _showInWebsite: 1
      _showInStore: 0
     - 
   label: Debug
      source_model: "Magento\\Config\\Model\\Config\\Source\\Yesno"
      _id: debug
      _translate: label
      _type: select
      _sortOrder: 85
      _showInDefault: 1
      _showInWebsite: 1
      _showInStore: 0
     - 
   label: "Payment Action"
      source_model: "Magento\\SamplePaymentGateway\\Model\\Adminhtml\\Source\\PaymentAction"
      _id: payment_action
      _translate: label
      _type: select
      _sortOrder: 110
      _showInDefault: 1
      _showInWebsite: 1
      _showInStore: 0
     - 
   label: "Payment From Applicable Countries"
      source_model: "Magento\\Payment\\Model\\Config\\Source\\Allspecificcountries"
      _id: allowspecific
      _translate: label
      _type: allowspecific
      _sortOrder: 130
      _showInDefault: 9
      _showInWebsite: 1
      _showInStore: 0
     - 
   label: "Payment From Specific Countries"
      source_model: "Magento\\Directory\\Model\\Config\\Source\\Country"
      _id: specificcountry
      _translate: label
      _type: multiselect
      _sortOrder: 140
      _showInDefault: 1
      _showInWebsite: 1
      _showInStore: 0
     - 
   label: "Sort Order"
      frontend_class: "validate-number"
      _id: sort_order
      _translate: label
      _type: text
      _sortOrder: 160
      _showInDefault: 1
      _showInWebsite: 1
      _showInStore: 0
    _id: sample_gateway
    _translate: label
    _type: text
    _sortOrder: 1
    _showInDefault: 1
    _showInWebsite: 1
    _showInStore: 1
   _id: payment
 "_xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance"
 "_xsi:noNamespaceSchemaLocation": "urn:magento:module:Magento_Config:etc/system_file.xsd"

thanks!

1 ACCEPTED SOLUTION

Accepted Solutions

Re: YAML configuration files

The main reason we use XML is it allows XSD validation to help spot syntax errors. While in a tool such as PHP Storm, it will tell you syntax errors as you type. We had a lot of problems in M1 with people wasting time trying to find bugs due to a minor spelling error not being picked up. For some files (like layout files) this is quite important due to their complexity.

 

I know it is less "trendy" these days. XML, JSON, YML, different formats come into vogue at times. I do agree XML is verbose, but until tools like PHP Storm can validate YML files as you type, spending the effort to move would go back to the older situation of syntax errors not being picked up. This might be okay for short files, but the benefit of spending the time to move formats appears to be its easier to read; the negative is no IDE validation (plus the effort to move). I guess I would like to see some strong arguments of why to invest in this over other areas, given there are negatives of the change as well.

View solution in original post

4 REPLIES 4

Re: YAML configuration files

Alan Storm had similar thoughts 4 years ago while analysing Magento 1.x: http://alanstorm.com/magento_config_a_critique_and_caching#comment-508037764

Re: YAML configuration files

The main reason we use XML is it allows XSD validation to help spot syntax errors. While in a tool such as PHP Storm, it will tell you syntax errors as you type. We had a lot of problems in M1 with people wasting time trying to find bugs due to a minor spelling error not being picked up. For some files (like layout files) this is quite important due to their complexity.

 

I know it is less "trendy" these days. XML, JSON, YML, different formats come into vogue at times. I do agree XML is verbose, but until tools like PHP Storm can validate YML files as you type, spending the effort to move would go back to the older situation of syntax errors not being picked up. This might be okay for short files, but the benefit of spending the time to move formats appears to be its easier to read; the negative is no IDE validation (plus the effort to move). I guess I would like to see some strong arguments of why to invest in this over other areas, given there are negatives of the change as well.

Re: YAML configuration files

thank you very much, that makes sense! 

 

I've downloaded some plugins to make using xml easier in phpstorm. There's also a gulp plugin to convert yaml to xml I could try out if I really want to go down that route.

Re: YAML configuration files

Yes xml can have validation and other cool things and I agree with that. (btw on move node the destination attribute value is always invalid "cannot resolve symbol" in php storm)... But have you ever personally tried to modify deep nested elements in checkout_index_index.xml (without ultrawide monitor, for example on 13" macbook pro)? you just can´t keep track where you are in the file. yep... This is more about how checkout js layout is configured, its pain even in PHP over layout processor. 

 

Generally there is little problem with templating which works great with default magento design, but let´s be honest, html structure of default magento theme is not that great for customization, good responsivnes, it can be partly done but it´s hardcore css hacking ending up with hard to maintain css, hard to reuse css(less)...

 

Lot of times I need to repeat myself. since our page content on front-end is wrapped into 2-3 divs to get perfect responsiveness in all current or future use cases. The page content includes:

- Header (page title, breadcrumbs, banner background) for all pages excluding product page and home page

- sidebar (optional)

- page content

 

So in each layout xml, I need to create this layout structure since the main div.page has also a bonus class based on which page you are on (product detail, product listing, checkout, cart....). And this applies to multiple things. This was only one example.

 

It this scenario it would be fine to have some xml tag like <referenceContainer addClass or changeClass.... so instead of recreating the front-end layout in each xml i can define it generally and then just use <referenceContaner name="xxx" changeClass="page page--cart" /> <move element="magentoDefaultPageContent" destination="xxx" />

 

For blocks there is a ifconfig=xyz there should be also (for blocks and containers also while referencing) a if="namespace/SomeConditionProvider.php"  and in SomeConditionProvider some execute method that will return true or false. 

 

Also found a very bad practice...: If the layered navigation is rendered after the product list then the product sort order is not working. WTH? 

 

Also: Europe is not USA, 80+% of the time there is a need to have layered navigation price filter that includes tax. I get it that it´s also missing because of performance, and in USA the prices are most of the time displayed without tax even in offline stores. But this is a must have feature to turn on off in store configuration. I have tried to search for some tutorials or guides how to do it. We ended up disabling price filter... Since I have not found any direct explanation, guide or anything from which I can understand what I need to do to achieve it... if someone filtered 0-30€ products with price of 35€ (incl. tax) were visible because in europe the people are used to see prices incl. tax.

 

Also: the wysiwyg editor is very out of date. 

Also: it´s 2018 still no default support to have image assigned to cms page.

Also: it´s 2018 still no possibility to add cms page to main navigation, its categories only.

Also: The cart page is empty but the minicart contains products (sometimes).

Also: No multimedia management (images, pdf, other files) c´mon..!! Client asked us where he can upload PDF, I was shocked that I need to develop a module to allow pdf uploads... really?

Also: After getting loged out automatically, my name, the account details link are still visible on top navigation. after clicking on it i am redirected to login. Imageine a internet coffe or some public computer where you go to shop. you log out and your name is visible because some data in localstorage of the buggy knockoutjs are still there.

 

I am using magento 2 from version 2.0 now I am on 2.2.3, there was lot of improvements. It´s moving in good direction. I love most of the things in magento. But it´s the most complex, most professional eCommerce platforms and it has so so much missing elements to make it usable for end-users, that even a primitive cms from 8 years ago when i started as developer had more UX for editing pages managing media and others... also compare how much time you need to add custom field to cms page in wordpress (10 minutes or less) 2-3 hours in magento, plus downtime of redeploying (cache, upgrade, compilation,...). or i ma doing something wrong?

 

Our clients eshop has only about 100 product images, when i downloaded some image optimalisation plugin i have noticed that there are 28000 images to optimize and we are using only 4 different image sizes... It shoudl be maximum of 400 images to optimize.

 

Yes  I am used to how wordpress works, in terms of admin user experience and also as developer. Both are different architectures, bothare made for different puirposes and I accept that, also I  kind of like most parts of the magento architecture. But it´s no excuse for not having some end user experience.