0

In Magento 2 ui_compoments were introduced to describe grids and forms.

However I would like to know which class of magento converts for example the file:

vendor/magento/module-customer/view/base/ui_component/customer_form.xml

For the .phtml template

So at this point I check if a post is allowed to change a field.

1 Answer 1

2

Well, the thing about uiComponents is that they don't work like blocks where you would have a .phtml file and class (Block) that passes data to it.

From a high level, the customer_form.xml is just a configuration file, that gets passed to the frontend (browser) as JSON.

The configuration data that you set in customer_form.xml is then eventually passed into the defaults object of the uiComponent's respective module (aka model): https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Ui/view/base/web/js/form/form.js#L163

This tells the module what to render (amongst many other things) and is bound to a scope (and a template) which allows you to leverage the methods defined in your model (enter knockout js magic): http://devdocs.magento.com/guides/v2.1/ui_comp_guide/concepts/ui_comp_config_flow_concept.html

The bootstrap.js binds the component as a Model behind this View (template) using Knockout bindings. The UI components are now displayed on the page, and are fully interactive.

But, uiComponents are recursive, which is why it's easily expressed in XML, and each child component is bound to their own scopes: templates, and models.

An example of a child component (in the context of the Form component) is the fieldset component: https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Ui/view/base/web/js/form/components/fieldset.js#L15

Take a look at the defaults object. This is a good example of a uiComponent defining it's own template file (in this case: 'ui/form/fieldset')


So to answer your question/request:

I would like to know which class of magento converts for example the file: vendor/magento/module-customer/view/base/ui_component/customer_form.xml So at this point I check if a post is allowed to change a field.

There are a quite a lot of Javascript modules that "convert" that xml file to what you see on the admin panel. You can start at the Form.js module and work your way down to whatever you want to check.

At that point, you can add validation's (see this answer for validations: UI form validation in Magento 2), or you can extend a component and write a method that does some additional stuff before the POST request is sent off to the server.


One tiny exception to the whole "no .phtml files" thing is the special <htmlContent> uiCompoenent that allows you to call/render a block and a template: https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Ui/Component/HtmlContent.php


I hope that answers your question. It almost has nothing to do with ACL rules (as the title of the question suggests).. but hey, now you know how uiComponents work (hopefully).

But, just in case... I'll just leave this tutorial on ACL rules here too: https://www.magestore.com/magento-2-tutorial/3194-2/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.