Jump to content

[SOLVED] Fields, Templates and Fieldgroups - how do they interact?


Gadgetto
 Share

Recommended Posts

33 minutes ago, Gadgetto said:

My question was regarding 'fieldgroups' and how they interact with fields and templates when installing things via API.

Fieldgroups currently are just an additional layer of "glue" between templates and fields, and for most they are just a few additional lines to write when assembling templates through the API. There are a few points where that additional layer can add some really nice magic to PW, but even most PW module developers never come across these.

For everyone not deeply into obscure PW vodoo magic, creating a template with fields is always:

  • Create a template
  • Create a fieldgroup with the same name as the template
  • Create your fields, save them and add them to the fieldgroup
  • Save the fieldgroup
  • Set the fieldgroup in the template
  • Save the template

Of course, you can reorder the steps as long as the objects are created before being used and saved after being changed.

9 minutes ago, Gadgetto said:

Are Fieldgroups required for adding fields to templates? What are these for?

Yes, they are. As written above, they are just a necessary glue.

  • Like 7
  • Thanks 1
Link to comment
Share on other sites

1 hour ago, BitPoet said:

Fieldgroups currently are just an additional layer of "glue" between templates and fields, and for most they are just a few additional lines to write when assembling templates through the API. There are a few points where that additional layer can add some really nice magic to PW, but even most PW module developers never come across these.

For everyone not deeply into obscure PW vodoo magic, creating a template with fields is always:

  • Create a template
  • Create a fieldgroup with the same name as the template
  • Create your fields, save them and add them to the fieldgroup
  • Save the fieldgroup
  • Set the fieldgroup in the template
  • Save the template

Of course, you can reorder the steps as long as the objects are created before being used and saved after being changed.

Yes, they are. As written above, they are just a necessary glue.

Hey, great - that's exactly the information I needed! Thank you!

2 last questions:

1) What if I'd like to add fields after the template was saved and how can I add them to the same fieldgroup?

2) Is there always only one field group per template or will/can there be more than one?

Link to comment
Share on other sites

10 minutes ago, Gadgetto said:

1) What if I'd like to add fields after the template was saved and how can I add them to the same fieldgroup?

Just add them to the template's fieldgroup.

$fg = $template->fieldgroup;
$fg->add($field);
$fg->save();

 

12 minutes ago, Gadgetto said:

2) Is there always only one field group per template or will/can there be more than one?

It is save to assume that there is only one fieldgroup, the one which you can access through $template->fieldgroup (or $template->fields, which is just an alias).

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

1 minute ago, BitPoet said:

Just add them to the template's fieldgroup.


$fg = $template->fieldgroup;
$fg->add($field);
$fg->save();

 

It is save to assume that there is only one fieldgroup, the one which you can access through $template->fieldgroup (or $template->fields, which is just an alias).

Thanks a lot! Thats all for now! ?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...