Dynamic Settings Array in Magento 2.0

February 22, 2016 / Posted in Magento, Magento 2 by Mishel Soiko
Dynamic Settings Array in Magento 2.0
Download PDF

In order to save dynamic settings array in one field, a default FieldArray is used.

Navigate to:

Stores => Configuration => Catalog => Inventory

Dynamic Settings Array in Magento 2.0

This is really convenient.

Such a field can be useful for any options list that is being extended. You can add new and delete existing options.

Here is how I define ranges.

Dynamic Settings Array in Magento 2.0

But it’s also possible to use it for displaying dynamic lists with editable content. In our case, it is used in the Product Sorting extension to display generated sortings.

Dynamic Settings Array in Magento 2.0

So let’s check the details of the example, as here we make multiple changes to the default field.

I had to add several custom fields such as: checkbox, link.

Let’s check how to use it:

Create a new Field in system.xml

It’s kind of easy: in the block, you describe your table, and the model influences the saving process.

Our block should contain the following:

This is a basis that is necessary to create and influence the saving process.

Let’s check the details of the AbstractFieldArray and find out what it can do.

In the previous example, a separate renderer could be created for each column. If the renderer was false, an empty field <input /> would be created.

And the renderer block that describes our new field. In this particular case it describes the checkbox.

The column can have a few more described parameters except label and renderer.

They are default in renderer. And we added them for our checkbox: style, class, size.

In the AbstractFieldArray class you can also find a function for customizing the saved fields.

In this article we checked an array as a default field.

You can also check this article to find out about creating unique fields and how they can be improved by using jQuery UI.



Post a new comment