thesilentman VIP
Total posts: 33
06 Oct 2015 10:10

Hi,

I am wondering if it's better to use $item->fields_by_key instead of $items->fields_by_id in my custom templates (and in my custom fields where I reference other fields)...

I ask, because the thing I am developing with Cobalt is on a development server and I would like to make a Pack out of it to install it on the production server when it's ready, without mixing up references. Unfortunately I havent found any docs on how Packs function in this aspect.

Last Modified: 07 Oct 2015


Sergey
Total posts: 13,748
07 Oct 2015 06:12

Pack will replace field IDs with new IDs and keys wil be the same.

Keys have to be used, when your template have to support multiple type. So for example there is Price field in every type template is going to show. It is the same field but different ID in every type. You position fields_by_key in one place and it will show price of any type.

Also note that when you create parameter for template where fields are selected, the name of the parameter have to start with field_id_. This is how Pack instalator knows that this is parameter where field ID have to be updated.


thesilentman VIP
Total posts: 33
07 Oct 2015 09:38

Sergey Pack will replace field IDs with new IDs and keys wil be the same.

This confirms my understanding of keys.

Keys have to be used, when your template have to support multiple type. So for example there is Price field in every type template is going to show. It is the same field but different ID in every type. You position fields_by_key in one place and it will show price of any type.

OK, understood.

Also note that when you create parameter for template where fields are selected, the name of the parameter have to start with field_id_. This is how Pack instalator knows that this is parameter where field ID have to be updated.

I think I understand, this one. Not sure though, could you elaborate?

Also:

If I have referenced a field_id in a custom field of mine (for example my text counter field, which references a textarea field), will the pack installer go through the json-config and update the field id appropriately in the newly installed Cobalt dataset?

For example, lets assume that the id of the textarea that I am referencing in my development environment is '5' and the production environment has already 10 other fields. Also assume that PACK will install the fields in the same order as they are in the development environment. Then the field with id 5 in the dev environment, would have id 15 in the production environment.

Will Pack correctly change the references (also in json-config-files) from field id 5 to field id 15?


Sergey
Total posts: 13,748
07 Oct 2015 15:02

thesilentman I think I understand, this one. Not sure though, could you elaborate?

When Pack is created install.php script is applied with is triggered after instalation. This script to through parameters of all templates look any parameter start with field_id_ and replace IDs. Fo instance on you local site fiel Price is ID 10, but after Pack install it on other Jooomla it become ID 23. But in template parameters 10 was saved for field in first column in advansed table template (check it is there). If we do not update it, template will look for ID 10 and will not find it.

Template configurations stored in config folder as JSON files. So i open it and update it and replace 10 to 23.

thesilentman Will Pack correctly change the references (also in json-config-files) from field id 5 to field id 15?

Yes. If you have this field selected in template parameters for example you what to create template position and in template parameter you select what field should be in that position, pack will update that too if the name of the parameter starts with field_id_. For example field_id_position1


thesilentman VIP
Total posts: 33
07 Oct 2015 17:40

Great, just as I expected it to work! (BTW I have seen a lot of other extensions where things do not work as I expected...) Thank you very much Sergey,

closing this now.

Powered by Cobalt