8000 Add index definitions to the data dictionary form/Separate index form by beeyayjay · Pull Request #4375 · GetDKAN/dkan · GitHub
[go: up one dir, main page]

Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2c2d0e4
Initial commit of updates to include indexes and index fields to the …
kaise-lafrai Apr 29, 2024
5396653
Added working cancel button for index, fixed errors appearing in log
kaise-lafrai May 14, 2024
bb42cf8
Removed unused code, fixed index fields cancel button
kaise-lafrai May 20, 2024
5e0ee4c
Added validation for index fields form, refactored code, refactored t…
kaise-lafrai May 24, 2024
e529acc
Fully functional edit experience for index fields (#4204)
kaise-lafrai Jul 8, 2024
620bced
Editable Index (#4239)
kaise-lafrai Aug 1, 2024
2250243
Index UI unit tests (#4262)
dmundra Aug 19, 2024
b7f844b
Updated data dictionary widget functional test to test all fields in …
dmundra Aug 29, 2024
b10bd49
Added Indexes edit unit tests (#4266)
dmundra Aug 30, 2024
567107f
Some simple code cleanup (white space, removal of commented out code,…
dmundra Sep 5, 2024
a9ccde9
WCMS-20047: Data Dictionary Documentation (#4271)
rovcase Sep 6, 2024
bb76f74
Data dictionary indexes code refactoring (#4280)
dmundra Sep 10, 2024
c7d7cfe
Reverted changes to checkIndexEditingField and checkIndexEditing. Upd…
dmundra Sep 10, 2024
4b4cf50
Adding code comments. (#4289)
dmundra Sep 18, 2024
ea018c7
Dictionary-Widget: Streamline the button labels for the Index and Ind…
rovcase Oct 24, 2024
ffb4d44
Provisional commit
Nov 27, 2024
ae7e367
In progress
Dec 3, 2024
a320129
Added indexes to admin view.
Dec 3, 2024
53fe56f
Temp save
Dec 4, 2024
0d46835
Temp save
Dec 4, 2024
2f45d07
Temp save
Dec 9, 2024
ec4fdf8
Temp save
Dec 9, 2024
058a91a
Index keyname changes and bug fixes.
Dec 12, 2024
1f3c275
Other indexes.
Jan 2, 2025
982d12f
Index edit works.
Jan 5, 2025
326d0b5
Add index field and cancel work.
Jan 5, 2025
69ee91f
Some cleanup.
Jan 6, 2025
622f4a9
More stuff
Jan 6, 2025
c9b743b
Some cleanup
Jan 6, 2025
3e82443
Updated data dictionary admin list. Added 'Add index' link.
Jan 6, 2025
a3bf332
Removed test field and made index length optional.
Jan 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Index keyname changes and bug fixes.
  • Loading branch information
Beth Jacobson committed Jan 6, 2025
commit 058a91a2ddb922dd970ed6964fa8a737c987683a
14 changes: 7 additions & 7 deletions modules/data_dictionary_widget/src/Fields/FieldCallbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static function updateFormatOptions(array &$form, FormStateInterface $for
public static function editSubformCallback(array &$form, FormStateInterface $form_state) {
// Get the current fields data.
$current_dictionary_fields = $form["field_json_metadata"]["widget"][0]["dictionary_fields"]["data"]["#rows"] ?? [];
$current_index_fields = $form["field_json_metadata"]["widget"][0]["indexes"]["fields"]["data"]["#rows"] ?? [];
// $current_index_fields = $form["field_json_metadata"]["widget"][0]["dictionary_fields"]["data"]["#rows"] ?? [];
// Get the field index from the triggering op attribute
// so we can use it to store the respective field later.
$op_index = explode("_", $form_state->getTriggeringElement()['#op']);
Expand Down Expand Up @@ -89,7 +89,7 @@ public static function editSubformCallback(array &$form, FormStateInterface $for
// Let's retain the fields that are already stored on the form,
// but aren't currently being modified.
$form_state->set('current_dictionary_fields', $current_dictionary_fields);
$form_state->set('current_index_fields', $current_index_fields);
// $form_state->set('current_dictionary_fields', $current_index_fields);
// Let's rebuild the form.
$form_state->setRebuild();
}
Expand All @@ -102,12 +102,12 @@ public static function addSubformCallback(array &$form, FormStateInterface $form
$op = $trigger['#op'];
$form_state->set('add_new_field', '');
// Get the current fields data.
$current_dictionary_fields = $form["field_json_metadata"]["widget"][0]["dictionary_fields"]["data"]["#rows"];
$current_index_fields = $form["field_json_metadata"]["widget"][0]["dictionary_fields"]["data"]["#rows"];
$current_index = $form["field_json_metadata"]["widget"][0]['indexes']["data"]["#rows"];
$current_index_fields = $form["field_json_metadata"]["widget"][0]['indexes']["fields"]["data"]["#rows"] ?? [];
// $current_index_fields = $form["field_json_metadata"]["widget"][0]['indexes']["fields"]["data"]["#rows"] ?? [];

if ($current_dictionary_fields) {
$form_state->set('current_dictionary_fields', $current_dictionary_fields);
if ($current_index_fields) {
$form_state->set('current_dictionary_fields', $current_index_fields);
}

if ($op === 'cancel') {
Expand All @@ -125,7 +125,7 @@ public static function addSubformCallback(array &$form, FormStateInterface $form
$form_state->set('cancel', FALSE);
}

$form_state->set('current_index_fields', $current_index_fields);
$form_state->set('current_dictionary_fields', $current_index_fields);
$form_state->set('current_index', $current_index);
$form_state->setRebuild();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static function validateField(FormStateInterface &$form_state, $field_key
['data', $index, 'field_collection']))) {
$field_value = $form_state->getValue(array_merge($path,
['data', $index, 'field_collection', $field_key]));
$error_field = "field_json_metadata][0][dictionary_fields][edit_fields][$index][$field_key";
$error_field = "field_json_metadata][0][dictionary_fields][edit_fields][$index][$field_key]";
}
elseif ($form_state->hasValue(array_merge($path,
['field_collection', 'group', $field_key]))) {
Expand Down
10 changes: 5 additions & 5 deletions modules/data_dictionary_widget/src/Indexes/IndexFieldButtons.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public static function addIndexFieldButton() {
return [
'#type' => 'submit',
'#value' => 'Add field to index',
'#name' => 'add_index_field',
'#name' => 'add_field',
'#access' => TRUE,
'#op' => 'add_new_index_field',
'#op' => 'add_new_field',
'#submit' => [
[
'\Drupal\data_dictionary_widget\Indexes\IndexFieldCallbacks',
Expand Down Expand Up @@ -105,7 +105,7 @@ public static function editIndexButtons($indexKey) {
*/
public static function submitIndexFieldButton($location, $indexKey) {
$callbackClass = $location == 'edit' ? 'indexEditSubformCallback' : 'indexAddSubformCallback';
$op = !empty($indexKey) ? 'update_' . $indexKey : 'add_index_field';
$op = is_int($indexKey) ? 'update_' . $indexKey : 'add_field';
$value = $location == 'edit' ? 'Save index field edit' : 'Save field to index';
// Index fields cannot be edited once submitted so we use the same function
// for both add and edit.
Expand Down Expand Up @@ -166,7 +166,7 @@ public static function submitIndexFieldButton($location, $indexKey) {
0,
'indexes',
'fields',
'edit_index_fields',
'edit_fields',
$indexKeyExplode[3],
'name',
],
Expand All @@ -175,7 +175,7 @@ public static function submitIndexFieldButton($location, $indexKey) {
0,
'indexes',
'fields',
'edit_index_fields',
'edit_fields',
$indexKeyExplode[3],
'length',
],
Expand Down
100 changes: 48 additions & 52 deletions modules/data_dictionary_widget/src/Indexes/IndexFieldCallbacks.php
6284
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,36 @@ public static function indexAddSubformCallback(array &$form, FormStateInterface
$current_index_fields = $form["field_json_metadata"]["widget"][0]['indexes']["fields"]["data"]["#rows"] ?? [];

if ($current_index_fields) {
$form_state->set('current_index_fields', $current_index_fields);
$form_state->set('current_dictionary_fields', $current_index_fields);
}

// If cancelling index field.
if ($op === 'cancel_index_field') {
// Set the display to show the current index fields values.
$form_state->set('cancel_index_field', TRUE);
// Hide the field collection.
$form_state->set('add_new_index_field', '');
$form_state->set('add_new_field', '');
}

// If adding new index field, this is triggered when you click the button to
// 'Add'
if ($op === 'add_new_index_field') {
if ($op === 'add_new_field') {
// @TODO not being used so maybe removable or update the comment.
$form_state->set('add_index_field', '');
$form_state->set('add_field', '');
// Get the form fields for adding new index fields.
$add_index_fields = IndexFieldAddCreation::addIndexFields($current_index_fields);
// Set the fields in the field collection.
$form_state->set('add_new_index_field', $add_index_fields);
$form_state->set('add_new_field', $add_index_fields);
// @TODO not being used so maybe removable or update the comment.
$form_state->set('index_added', FALSE);
// @TODO not being used so maybe removable or update the comment.
$form_state->set('adding_new_index_fields', TRUE);
}

// If saving new index field.
if ($op === 'add_index_field') {
if ($op === 'add_field') {
// @TODO not being used so maybe removable or update the comment.
$form_state->set('add_new_index_field', '');
$form_state->set('add_new_field', '');
// Get and save the entered values.
$form_state->set('new_index_fields', $form_state->getUserInput());
// @TODO not being used so maybe removable or update the comment.
Expand All @@ -66,7 +66,7 @@ public static function indexAddSubformCallback(array &$form, FormStateInterface
// but aren't currently being modified.
$form_state->set('current_dictionary_fields', $current_dictionary_fields);
$form_state->set('current_index', $current_index);
$form_state->set('current_index_fields', $current_index_fields);
$form_state->set('current_dictionary_fields', $current_index_fields);
// Let's rebuild the form.
$form_state->setRebuild();
}
Expand All @@ -81,31 +81,29 @@ public static function indexAddCallback(array &$form, FormStateInterface $form_s
// Get the current fields data.
$current_dictionary_fields = $form["field_json_metadata"]["widget"][0]["dictionary_fields"]["data"]["#rows"];
$current_index = $form["field_json_metadata"]["widget"][0]["indexes"]["data"]["#rows"];
$current_index_fields = $form["field_json_metadata"]["widget"][0]['indexes']["fields"]["data"]["#rows"] ?? NULL;
// $current_index_fields = $form["field_json_metadata"]["widget"][0]['indexes']["fields"]["data"]["#rows"] ?? NULL;
// Initialize the various field storage values.
$form_state->set('add_new_index_field', '');
$form_state->set('new_index_fields', '');
$form_state->set('add_new_index', '');
// @TODO not being used so maybe removable or update the comment.
$form_state->set('adding_new_index_fields', FALSE);

if ($current_index) {
$form_state->set('current_index', $current_index);
// $form_state->set('add_new_index_field', '');
// $form_state->set('new_index_fields', '');
// $form_state->set('add_new_index', '');
// // @TODO not being used so maybe removable or update the comment.
// $form_state->set('adding_new_index_fields', FALSE);

if ($current_dictionary_fields) {
$form_state->set('current_dictionary_fields', $current_dictionary_fields);
}

// If cancelling index.
if ($op === 'cancel_index') {
// Set the display to show the current index values.
$form_state->set('cancel_index', TRUE);
if ($op === 'cancel') {
$form_state->set('cancel', TRUE);
}

// If adding new index, this is triggered when you click the button to
// 'Add index'
if ($op === 'add_new_index') {
if ($op === 'add_new_field') {
// Get the form fields for adding new index.
$add_new_index = IndexFieldAddCreation::addIndex();
// Set the new_index values to empty.
$form_state->set('new_index', '');
$form_state->set('add_new_field', '');
// Set the fields in the field collection.
$form_state->set('add_new_index', $add_new_index);
}
Expand All @@ -128,7 +126,7 @@ public static function indexAddCallback(array &$form, FormStateInterface $form_s
// but aren't currently being modified.
$form_state->set('current_dictionary_fields', $current_dictionary_fields);
$form_state->set('current_index', $current_index);
$form_state->set('current_index_fields', $current_index_fields);
$form_state->set('current_dictionary_fields', $current_index_fields);
// Let's rebuild the form.
$form_state->setRebuild();
}
Expand All @@ -145,22 +143,22 @@ public static function indexEditSubformCallback(array &$form, FormStateInterface
$op_index = explode('_', $trigger['#op']);
// Get the current fields data.
$current_index_fields = $form["field_json_metadata"]["widget"][0]["dictionary_fields"]["data"]["#rows"];
$currently_modifying_index_fields = $form_state->get('dictionary_fields_being_modified') != NULL ? $form_state->get('index_fields_being_modified') : [];
$currently_modifying = $form_state->get('dictionary_fields_being_modified') != NULL ? $form_state->get('dictionary_fields_being_modified') : [];
$currently_modifying_index_fields = $form_state->get('dictionary_fields_being_modified') ?? [];
// $currently_modifying = $form_state->get('dictionary_fields_being_modified') != NULL ? $form_state->get('dictionary_fields_being_modified') : [];

// If the op (trigger) contains abort,
// We're canceling the field we're currently modifying so unset it.
if (str_contains($op, 'abort')) {
unset($currently_modifying_index_fields[$op_index[4]]);
unset($currently_modifying_index_fields[$op_index[1]]);
}

// If the op (trigger) contains delete,
// We're deleting the field we're editing so...
if (str_contains($op, 'delete')) {
// Unset it from being currently modified.
unset($currently_modifying_index_fields[$op_index[4]]);
unset($currently_modifying_index_fields[$op_index[1]]);
// Remove the respective field/data from the form.
unset($current_index_fields[$op_index[4]]);
unset($current_index_fields[$op_index[1]]);
}

// If the op (trigger) contains update,
Expand All @@ -169,29 +167,27 @@ public static function indexEditSubformCallback(array &$form, FormStateInterface
// Get the entered data.
$update_values = $form_state->getUserInput();
// Unset the respective currently modifying field.
unset($currently_modifying_index_fields[$op_index[4]]);
unset($currently_modifying_index_fields[$op_index[1]]);
// Unset the respective field/data from the form.
unset($current_index_fields[$op_index[4]]);
unset($current_index_fields[$op_index[1]]);
// Update the respective current field data with our new input data.
$current_index_fields[$op_index[4]] = IndexFieldValues::updateIndexFieldValues($op_index[4], $update_values, $current_index_fields);
$current_index_fields[$op_index[1]] = IndexFieldValues::updateIndexFieldValues($op_index[1], $update_values, $current_index_fields);
// Sort the current index fields data.
ksort($current_index_fields);
}

// If the op (trigger) contains edit
// We're editing a specific field so...
if (str_contains($op, 'edit_index_field')) {
if (str_contains($op, 'edit')) {
// Set the field we're modifying to that field.
$currently_modifying_index_fields[$op_index[4]] = $current_index_fields[$op_index[4]];
$currently_modifying_index_fields[$op_index[1]] = $current_index_fields[$op_index[1]];
}

// Let's retain the fields that are being modified.
$form_state->set('dictionary_fields_being_modified', $currently_modifying);
$form_state->set('index_fields_being_modified', $currently_modifying_index_fields);
$form_state->set('dictionary_fields_being_modified', $currently_modifying_index_fields);
// Let's retain the fields that are already stored on the form,
// but aren't currently being modified.
$form_state->set('current_index_fields', $current_index_fields);
$form_state->set('current_dictionary_fields', $current_dictionary_fields);
$form_state->set('current_dictionary_fields', $current_index_fields);
// Let's rebuild the form.
$form_state->setRebuild();
}
Expand All @@ -207,12 +203,12 @@ public static function indexEditCallback(array &$form, FormStateInterface $form_
// We split the key to get the index location.
$op_index = explode('_', $trigger['#op']);
// Get the current fields data.
$current_index_fields = $form['field_json_metadata']['widget'][0]['indexes']['fields']['data']['#rows'] ?? [];
// $current_index_fields = $form['field_json_metadata']['widget'][0]['indexes']['fields']['data']['#rows'] ?? [];
$current_index = $form['field_json_metadata']['widget'][0]['indexes']['data']['#rows'] ?? [];
$current_dictionary_fields = $form['field_json_metadata']['widget'][0]['dictionary_fields']['data']['#rows'] ?? [];
$currently_modifying_index_fields = $form_state->get('index_fields_being_modified') != NULL ? $form_state->get('index_fields_being_modified') : [];
$current_index_fields = $form['field_json_metadata']['widget'][0]['dictionary_fields']['data']['#rows'] ?? [];
$currently_modifying_index_fields = $form_state->get('dictionary_fields_being_modified') != NULL ? $form_state->get('index_fields_being_modified') : [];
$currently_modifying_index = $form_state->get('index_being_modified') != NULL ? $form_state->get('index_being_modified') : [];
$currently_modifying_dictionary_fields = $form_state->get('dictionary_fields_being_modified') != NULL ? $form_state->get('dictionary_fields_being_modified') : [];
// $currently_modifying_dictionary_fields = $form_state->get('dictionary_fields_being_modified') != NULL ? $form_state->get('dictionary_fields_being_modified') : [];

// If the op (trigger) contains abort,
// We're canceling the index we're cu A93C rrently modifying so unset it.
Expand All @@ -221,7 +217,7 @@ public static function indexEditCallback(array &$form, FormStateInterface $form_
}
// We're canceling the index field we're currently modifying so unset it.
if (str_contains($op, 'abort_index_field_key')) {
unset($currently_modifying_index_fields[$op_index[4]]);
unset($currently_modifying_index_fields[$op_index[1]]);
}

// If the op (trigger) contains delete,
Expand All @@ -235,9 +231,9 @@ public static function indexEditCallback(array &$form, FormStateInterface $form_
// We're deleting the index field we're editing so...
if (str_contains($op, 'delete_index_field_key')) {
// Unset it from being currently modified.
unset($currently_modifying_index_fields[$op_index[4]]);
unset($currently_modifying_index_fields[$op_index[1]]);
// Remove the respective field/data from the form.
unset($current_index_fields[$op_index[4]]);
unset($current_index_fields[$op_index[1]]);
}

// If the op (trigger) contains update,
Expand All @@ -261,14 +257,14 @@ public static function indexEditCallback(array &$form, FormStateInterface $form_
}

// Let's retain the fields that are being modified.
$form_state->set('dictionary_fields_being_modified', $currently_modifying_dictionary_fields);
$form_state->set('index_fields_being_modified', $currently_modifying_index_fields);
$form_state->set('dictionary_fields_being_modified', $currently_modifying_index_fields);
// $form_state->set('index_fields_being_modified', $currently_modifying_index_fields);
$form_state->set('index_being_modified', $currently_modifying_index);
// Let's retain the fields that are already stored on the form,
// but aren't currently being modified.
$form_state->set('current_index_fields', $current_index_fields);
// $form_state->set('current_index_fields', $current_index_fields);
$form_state->set('current_index', $current_index);
$form_state->set('current_dictionary_fields', $current_dictionary_fields);
$form_state->set('current_dictionary_fields', $current_index_fields);
// Let's rebuild the form.
$form_state->setRebuild();
}
Expand All @@ -284,20 +280,20 @@ public static function subIndexEditFormAjax(array &$form, FormStateInterface $fo
* Ajax callback to return index fields.
*/
public static function subIndexFormAjax(array &$form, FormStateInterface $form_state) {
return $form["field_json_metadata"]["widget"][0]["indexes"]["fields"];
return $form["field_json_metadata"]["widget"][0]["dictionary_fields"];
}

/**
* Ajax callback to return indexes.
*/
public static function indexFormAjax(array &$form, FormStateInterface $form_state) {
$index_fields = $form["field_json_metadata"]["widget"][0]["indexes"]["fields"];
$index_fields = $form["field_json_metadata"]["widget"][0]["dictionary_fields"];

// Validation errors skip submit callbacks, this will set the index fields
// in the correct location.
if ($index_fields["data"]) {
$form["field_json_metadata"]["widget"][0]["indexes"]["field_collection"]["group"]["index"]["fields"] = $index_fields;
$form["field_json_metadata"]["widget"][0]["indexes"]["fields"]['#access'] = FALSE;
$form["field_json_metadata"]["widget"][0]["dictionary_fields"]['#access'] = FALSE;
}

return $form["field_json_metadata"]["widget"][0]["indexes"];
Expand Down
Loading
0