Skip to content

Commit

Permalink
Add all fields to Multiple Entries layout (#2106)
Browse files Browse the repository at this point in the history
## Testing

- Add `add_filter(
'gk/gravityview/view/new/show-all-fields-in-multiple-entries',
'__return_true' );`
- When added, create a new View
- Select a form with many fields (more than are shown in Gravity Forms
"Entries" screen)
- Select the Table layout

## What you should see:
- All fields should appear in the Mulitple Entries tab
- The first field should be linked to the Single Entry

## Items for @mrcasual 

- Name of the filter
- Code review

Resolves #2105

💾 [Build
file](https://www.dropbox.com/scl/fi/tegdbfhag7oot7gzbd0ct/gravityview-2.26-d54ac6091.zip?rlkey=2xmi4egevu21wu83sxt57nmzl&dl=1)
(d54ac60).
  • Loading branch information
mrcasual authored Aug 14, 2024
2 parents 9632d66 + e02b351 commit 18eed78
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 16 deletions.
61 changes: 45 additions & 16 deletions includes/class-admin-views.php
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,7 @@ function render_directory_active_areas( $template_id = '', $context = 'single',
* @since 2.17
* @internal Do not use this method directly. Use the `gravityview/view/configuration/fields` filter instead.
*
* @param array $fields A Widget configuration array.
* @param array $fields Multi-array of fields with first level being the field zones.
* @param \GV\View $view The View the fields are being pulled for. Unused in this method.
* @param int $form_id The form ID.
*
Expand All @@ -1387,40 +1387,69 @@ public function set_default_view_fields( $fields = array(), $view = null, $form_
return $fields;
}

$columns = GFFormsModel::get_grid_columns( $form_id );
/**
* Modify whether to initialize the Multiple Entries layout with all form fields or only the fields displayed in the Gravity Forms Entries table when creating a new View.
*
* @filter `gk/gravityview/view/configuration/multiple-entries/initialize-with-all-form-fields`
*
* @since TODO
*
* @param bool $show_all_fields Whether to include all form fields (true) or only the fields displayed in the Gravity Forms Entries table (false). Default: `false`.
* @param int $form_id The current form ID.
*/
$show_all_fields = apply_filters( 'gk/gravityview/view/configuration/multiple-entries/initialize-with-all-form-fields', false, $form_id );

$directory_fields = array();
if ( ! $show_all_fields ) {
$columns = GFFormsModel::get_grid_columns( $form_id );

foreach ( $columns as $column_id => $column ) {
$directory_fields = array();

$gv_field = GravityView_Fields::get_instance( $column['type'] );
foreach ( $columns as $column_id => $column ) {

if ( ! $gv_field ) {
continue;
}
$gv_field = GravityView_Fields::get_instance( $column['type'] );

$directory_fields[ uniqid( '', true ) ] = array(
'label' => \GV\Utils::get( $column, 'label' ),
'type' => $gv_field->name,
'id' => $column_id,
'form_id' => $form_id,
'show_as_link' => empty( $directory_fields ),
);
if ( ! $gv_field ) {
continue;
}

$directory_fields[ uniqid( '', true ) ] = array(
'label' => \GV\Utils::get( $column, 'label' ),
'type' => $gv_field->name,
'id' => $column_id,
'form_id' => $form_id,
'show_as_link' => empty( $directory_fields ),
);

}
}

$form = GV\GF_Form::by_id( $form_id );
$entry_fields = array();

foreach ( $form->form['fields'] as $gv_field ) {

$entry_fields[ uniqid( '', true ) ] = array(
'label' => $gv_field->label,
'type' => $gv_field->type,
'id' => $gv_field->id,
'form_id' => $form_id,
);
}

// If we're showing all fields, the entry fields are the same as the directory fields.
if ( $show_all_fields ) {
$directory_fields = $entry_fields;

// If we're showing all fields, we want to show the first field as a link.
foreach( $directory_fields as &$field ) {
$gf_field = GF_Fields::get( $field['type'] );

if ( ! $gf_field ) {
continue;
}

$field['show_as_link'] = true;
break; // Only show the first field as a link.
}
}

// Add Edit Entry to the bottom of the Single Entry configuration.
Expand Down
4 changes: 4 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ Beautifully display your Gravity Forms entries. Learn more on [gravitykit.com](h
* Fixed: Fatal error on the Edit Entry screen when Multiple Forms is enabled.
* Fixed: The ``:format` merge tag modifier on the Time field returned a UTC-adjusted time value.

__Developer Updates:__

* Added: `gk/gravityview/view/configuration/multiple-entries/initialize-with-all-form-fields` filter that, when set to `true`, initializes the Multiple Entries layout with all form fields when creating a new View. The default is `false`, which populates the View with only the fields configured in the Gravity Forms Entries table.

= 2.26 on August 8, 2024 =

This update resolves various issues, including compatibility with Yoast SEO, improves performance through enhanced View entries caching, and adds new functionality.
Expand Down

0 comments on commit 18eed78

Please sign in to comment.