📜 ⬆️ ⬇️

Group editing of resources (documents) using MIGXDB

I’m never tired of being surprised at the possibilities provided by the MIGX component from Bruno17 for MODX Revolution . It looks awkward and there are some mistakes, but there are no critical problems. Everything that is written in this article is relevant for MIGX version 2.5.8-pl (the last one at the moment).

Many use MIGX to create photo galleries , but its functionality is not limited to this. This is a real constructor for managing the data of any database tables. You can even display a list of child resources (MODX documents) in any container. This will be discussed in this article. Something I learned from the MIGDB documentation , but, as far as I understood, it is already rather outdated and much of what is described there simply does not work.



I will tell you how to make such a table with nested resources:

')
1. Open “Components” -> “MIGX”. Go to the "MIGX" tab. Click the Add Item button.
2. On the Settings tab, enter the name (Name) of the configuration, for example, “child_resources”. Click the "Run" button.
It would be very long to paint what where to click and where to enter, but let's make it easier. I will give the finished configuration, and you customize it for yourself.
3. Click the right mouse button on the line of our configuration and select "Export / Import".

In the field in the window that appears, insert the following JSON array:
Show
{ "formtabs":[ { "MIGX_id":1, "caption":" ", "print_before_tabs":"0", "fields":[ { "MIGX_id":1, "field":"pagetitle", "caption":"", "description":"", "description_is_code":"0", "inputTV":"", "inputTVtype":"", "configs":"", "sourceFrom":"config", "sources":"[]", "inputOptionValues":"", "default":"" }, { "MIGX_id":10, "field":"alias", "caption":"", "description":"", "description_is_code":"0", "inputTV":"", "inputTVtype":"", "configs":"", "sourceFrom":"config", "sources":"[]", "inputOptionValues":"", "default":"" }, { "MIGX_id":6, "field":"introtext", "caption":" ", "description":"", "description_is_code":"0", "inputTV":"", "inputTVtype":"textarea", "configs":"", "sourceFrom":"config", "sources":"[]", "inputOptionValues":"", "default":"" }, { "MIGX_id":7, "field":"image", "caption":"", "description":"", "description_is_code":"0", "inputTV":"image", "inputTVtype":"", "configs":"", "sourceFrom":"config", "sources":"[]", "inputOptionValues":"", "default":"" }, { "MIGX_id":4, "field":"price", "caption":"", "description":"", "description_is_code":"0", "inputTV":"price", "inputTVtype":"", "configs":"", "sourceFrom":"config", "sources":"[]", "inputOptionValues":"", "default":"" }, { "MIGX_id":5, "field":"context_key", "caption":"", "description":"", "description_is_code":"0", "inputTV":"", "inputTVtype":"listbox", "configs":"", "sourceFrom":"config", "sources":"[]", "inputOptionValues":"catalog||web", "default":"catalog" }, { "MIGX_id":2, "field":"template", "caption":"", "description":"", "description_is_code":"0", "inputTV":"", "inputTVtype":"hidden", "configs":"", "sourceFrom":"config", "sources":"[]", "inputOptionValues":"", "default":5 }, { "MIGX_id":8, "field":"show_in_tree", "caption":"  ?", "description":"", "description_is_code":"0", "inputTV":"", "inputTVtype":"listbox", "configs":"", "sourceFrom":"config", "sources":"[]", "inputOptionValues":"no==0||yes==1", "default":"" }, { "MIGX_id":9, "field":"published", "caption":"", "description":"", "description_is_code":"0", "inputTV":"", "inputTVtype":"hidden", "configs":"", "sourceFrom":"config", "sources":"[]", "inputOptionValues":"", "default":1 } ] }, { "MIGX_id":2, "caption":" ", "print_before_tabs":"0", "fields":[ { "MIGX_id":1, "field":"content", "caption":"", "description":"", "description_is_code":"0", "inputTV":"", "inputTVtype":"richtext", "configs":"", "sourceFrom":"config", "sources":"[]", "inputOptionValues":"", "default":"" } ] } ], "contextmenus":"recall_remove_delete", "actionbuttons":"addItem||bulk||toggletrash", "columnbuttons":"update||publish||unpublish||recall_remove_delete", "filters":[ { "MIGX_id":1, "name":"search", "label":"search", "emptytext":"...", "type":"textbox", "getlistwhere":{ "pagetitle:LIKE":"%[[+search]]%", "OR:longtitle:LIKE":"%[[+search]]%", "OR:content:LIKE":"%[[+search]]%" }, "getcomboprocessor":"", "combotextfield":"", "comboidfield":"", "comboparent":"", "default":"" } ], "extended":{ "migx_add":"", "formcaption":" ", "update_win_title":"", "win_id":"child_resources", "maxRecords":"", "addNewItemAt":"bottom", "multiple_formtabs":"", "extrahandlers":"", "packageName":"", "classname":"modResource", "task":"resconnections", "getlistsort":"id", "getlistsortdir":"desc", "use_custom_prefix":"0", "prefix":"", "grid":"", "gridload_mode":1, "check_resid":"0", "check_resid_TV":"", "join_alias":"", "has_jointable":"yes", "getlistwhere":"", "joins":"", "cmpmaincaption":"", "cmptabcaption":"", "cmptabdescription":"", "cmptabcontroller":"", "winbuttons":"", "onsubmitsuccess":"", "submitparams":"" }, "columns":[ { "MIGX_id":1, "header":"ID", "dataIndex":"id", "width":50, "sortable":true, "show_in_grid":1, "renderer":"", "clickaction":"", "selectorconfig":"", "renderchunktpl":"", "renderoptions":"[]" }, { "MIGX_id":2, "header":"", "dataIndex":"pagetitle", "width":300, "sortable":true, "show_in_grid":1, "renderer":"this.renderRowActions", "clickaction":"", "selectorconfig":"", "renderchunktpl":"", "renderoptions":"[]" }, { "MIGX_id":3, "header":"", "dataIndex":"price", "width":100, "sortable":true, "show_in_grid":1, "renderer":"", "clickaction":"", "selectorconfig":"", "renderchunktpl":"", "renderoptions":"[]" }, { "MIGX_id":4, "header":"", "dataIndex":"published", "width":100, "sortable":"false", "show_in_grid":1, "renderer":"this.renderCrossTick", "clickaction":"", "selectorconfig":"", "renderchunktpl":"", "renderoptions":"[]" }, { "MIGX_id":5, "header":"", "dataIndex":"deleted", "width":"", "sortable":"false", "show_in_grid":"0", "renderer":"", "clickaction":"", "selectorconfig":"", "renderchunktpl":"", "renderoptions":"[]" } ] } 


Ready resource management interface.
4. Create the configuration file /core/components/migx/configs/grid/grid.child_resources.config.inc.php with the following contents:

 <?php $this->customconfigs['idfield_local'] = 'parent'; $this->customconfigs['includeTVs'] = 1; $this->customconfigs['includeTVList'] = 'price,image'; 

As you guessed, includeTVList is a list of all the TVs that you need in a component.
5. Click the “child_resources” configuration line again and select “Edit”. Go "Formtabs" -> "Basic data" -> "Edit". A list of all fields opens. Here you need to configure the names of the fields and TV that you need.
6. As you can see, for the "image" field is set to "Input TV" - "image". If such a TV-parameter (additional field) has not yet been created, then you need to create it, assign the input type “Image” and make it available for the desired template. Also with the rest of the TV.
7. Open the editing of the template field, go to the Input Options tab, and in the Default Value field enter the template ID of the child resources that we will manage through our component. You should also configure the “context_key” field. Set the right contexts there.
8. Now you need to make the list of resources appear when editing resources with the appropriate template. Create a TV, for example with the name "child_resources". Input type specify “migxdb”, in the “Configurations” field enter the name of the configuration created earlier (“child_resources”).

Make this TV available for templates matching resource-containers.
9. On this one could finish, but because MIGX is still raw I had to fix the processors in the folder "/ processors / mgr / resconnections /". Take from here . You also need to update the code of the migx.class.php file.

Now everything should work as it should.
In this way, you can make controls for any data. Using MIGXDB, you can create and edit your tables in the database. This is written here .

Source: https://habr.com/ru/post/196396/


All Articles