Skip to content

One big group#8

Merged
JasonHoffmann merged 36 commits into
masterfrom
one-big-group
Jul 5, 2017
Merged

One big group#8
JasonHoffmann merged 36 commits into
masterfrom
one-big-group

Conversation

@JasonHoffmann

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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
Copy Markdown
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
Copy Markdown
Contributor Author

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

@jtsternberg

Copy link
Copy Markdown

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
Copy Markdown
Contributor Author

Oh right, perfect!

Comment thread cmb2-flexible-content-field.php Outdated
$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
Copy Markdown
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.

4 participants