Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

One big group #8

Merged
merged 36 commits into from Jul 5, 2017
Merged

One big group #8

merged 36 commits into from Jul 5, 2017

Conversation

JasonHoffmann
Copy link
Contributor

This takes a slightly different approach from #5. Instead of creating new groups for each set of fields, this replaces the existing field with a single group, then swaps fields in and out to render data.

Some advantages there:

  • Data in the form is not double-nested
  • No need to overwrite meta values since the group is structured properly
  • Can rely on CMB2 for more JS functionality, including removing rows and WYSIWYG initialization
  • Can pre-render WYSIWYG fields with data and template, so don't need to try to clone settings from existing WYSIWYG fields or output a WYSIWYG template on AJAX requests
  • Can use more of CMB2 classes and styles
  • Less code

The disadvantage being that the CMB2 Field instance has to be cloned and recreated fairly often, but that is really just building up an array, and it is more or less the same as creating a new group for each individual data block.

@JasonHoffmann
Copy link
Contributor Author

Also, something that would make this way easier in CMB2. If there was a way to edit a fields field_options parameter (it's currently protected), I wouldn't need to clone the group so often, since I can just populate the field_options array with the data I need.

@jtsternberg
Copy link

CMB2/CMB2@1882114 should help with that. Will just need to modify the field's options param before calling CMB2_Field::set_options() again. You can update the options param, by doing something like:

$field->set_prop( 'options', $new_modified_options );
$field->set_options();

@JasonHoffmann
Copy link
Contributor Author

Yea the problem was trying to modify it after set_options was already called. But that gives me an idea about storing some things beforehand...

@JasonHoffmann
Copy link
Contributor Author

Oh and thanks for the commit @jtsternberg! Should make things easier.

@jtsternberg
Copy link

Yea the problem was trying to modify it after set_options was already called.

Right, but now you can call set_options at any arbitrary time, to reset the field options array.

@JasonHoffmann
Copy link
Contributor Author

Oh right, perfect!

$field_group = $flexible_field->get_field_clone( $group_args );
$field_group->data_to_save = $values;

// // The saved array is used to hold sanitized values.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra comment marks

@JasonHoffmann JasonHoffmann merged commit a08270f into master Jul 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants