Last active
December 11, 2023 14:20
-
-
Save litzinger/5f7f8f4abba565ff976b22868f95db99 to your computer and use it in GitHub Desktop.
Proposed changes to EE's Fluid Field - See https://github.com/ExpressionEngine/ExpressionEngine/issues/1643 for past convos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- Model/FluidField_unedited.php 2023-07-17 11:25:23 | |
+++ Model/FluidField.php 2023-07-07 16:49:14 | |
@@ -119,7 +119,9 @@ | |
$rows = ee()->extensions->call( | |
'fluid_field_get_field_data', | |
$this->field_id, | |
- $this->field_data_id | |
+ $this->field_data_id, | |
+ $this->fluid_field_id, | |
+ $this->entry_id | |
); | |
} else { | |
ee()->db->where('id', $this->field_data_id); | |
@@ -143,7 +145,8 @@ | |
$field_data = ee()->extensions->call( | |
'fluid_field_get_all_data', | |
$field_data, | |
- $this->fluid_field_id | |
+ $this->fluid_field_id, | |
+ $this->entry_id | |
); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We have an array of fields but its not iterating them? This feels awkward. Changing it to the foreach seems to work fine with or without Publisher. I don't see negative side effects to making this change. | |
<?php | |
// $field_data is an array, regardless if it's a group of fields or single fields. | |
// Don't know why it's only accessing the first item in the array. This change works | |
// with the hook changes above, and without, and with single fields and grouped fields. | |
foreach ($fluid_field_data_groups as $field_data) { | |
$is_group = !is_null($field_data[0]->ChannelFieldGroup); | |
$view = ($is_group) ? 'fluid_field:fieldgroup' : 'fluid_field:field'; | |
$viewData = [ | |
'filters' => $filters, | |
'errors' => $this->errors, | |
'reorderable' => true, | |
'show_field_type' => false, | |
'field_filters' => $filter_options | |
]; | |
if ($is_group) { | |
$field_group = $field_data[0]->ChannelFieldGroup; // might want to eager load this | |
$viewData = array_merge($viewData, [ | |
'field_group' => $field_group, | |
'field_group_fields' => array_map(function ($field) use ($field_group) { | |
$f = $field->getField(); | |
$f->setName($this->name() . '[fields][field_' . $field->getId() . '][field_group_id_' . $field_group->getId() . '][field_id_' . $f->getId() . ']'); | |
return $f; | |
}, $field_data), | |
'field_name' => $field_group->short_name, | |
]); | |
$fields .= ee('View')->make($view)->render($viewData); | |
} else { | |
+ foreach ($field_data as $field_datum) { | |
+ $field = $field_datum->getField(); | |
+ $field->setName($this->name() . '[fields][field_' . $field_datum->getId() . '][field_group_id_0][field_id_' . $field->getId() . ']'); | |
+ $viewData = array_merge($viewData, [ | |
+ 'field' => $field, | |
+ 'field_name' => $field_datum->ChannelField->field_name, | |
+ ]); | |
+ $fields .= ee('View')->make($view)->render($viewData); | |
+ } | |
- $field = $field_data[0]->getField(); | |
- $field->setName($this->name() . '[fields][field_' . $field_data[0]->getId() . '][field_group_id_0][field_id_' . $field->getId() . ']'); | |
- $viewData = array_merge($viewData, [ | |
- 'field' => $field, | |
- 'field_name' => $field_data[0]->ChannelField->field_name, | |
- ]); | |
} | |
- $fields .= ee('View')->make($view)->render($viewData); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- ft.fluid_field_unedited.php 2023-07-17 11:21:04 | |
+++ ft.fluid_field.php 2023-07-15 07:12:15 | |
@@ -387,7 +387,16 @@ | |
$query->set($values); | |
$query->where('id', $fluid_field->field_data_id); | |
$query->update($fluid_field->ChannelField->getTableName()); | |
+ | |
+ if (ee()->extensions->active_hook('fluid_field_after_update_field') === true) { | |
+ ee()->extensions->call( | |
+ 'fluid_field_after_update_field', | |
+ $fluid_field, | |
+ $fluid_field->ChannelField->getTableName(), | |
+ $values | |
+ ); | |
} | |
+ } | |
private function addField($order, $group, $field_id, array $values) | |
{ | |
@@ -424,6 +433,15 @@ | |
$fluid_field->field_data_id = $id; | |
$fluid_field->save(); | |
+ | |
+ if (ee()->extensions->active_hook('fluid_field_after_add_field') === true) { | |
+ ee()->extensions->call( | |
+ 'fluid_field_after_add_field', | |
+ $fluid_field, | |
+ $fluid_field->ChannelField->getTableName(), | |
+ $values, | |
+ $id | |
+ ); | |
+ } | |
} | |
private function removeField($fluid_field) |
Can't change the param order ExpressionEngine/ExpressionEngine#3927 (comment)
Need to update fork to EE 7.4, and apply these changes.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In the ft.fluid_field.php file in the addField and updateField methods, between the two hooks wrap the db update calls in