From ed52003042adaa8ba798c4bb70f8190ff4285202 Mon Sep 17 00:00:00 2001 From: Kaise Lafrai <56809719+kaise-lafrai@users.noreply.github.com> Date: Thu, 1 Aug 2024 15:49:23 -0400 Subject: [PATCH] Editable Index (#4239) --- .../src/Fields/FieldCallbacks.php | 6 +- .../src/Fields/FieldOperations.php | 14 +- .../src/Indexes/IndexFieldAddCreation.php | 12 +- .../src/Indexes/IndexFieldButtons.php | 64 +++++++-- .../src/Indexes/IndexFieldCallbacks.php | 77 +++++++++- .../src/Indexes/IndexFieldCreation.php | 12 +- .../src/Indexes/IndexFieldEditCreation.php | 70 ++++++--- .../src/Indexes/IndexFieldOperations.php | 135 +++++++++++++----- .../src/Indexes/IndexFieldValues.php | 17 ++- .../FieldWidget/DataDictionaryWidget.php | 110 ++++++++------ .../custom-index-fields-table.html.twig | 3 +- .../templates/custom-index-table.html.twig | 2 +- .../Unit/DataDictionaryWidgetBuildTest.php | 42 ++++-- 13 files changed, 420 insertions(+), 144 deletions(-) diff --git a/modules/data_dictionary_widget/src/Fields/FieldCallbacks.php b/modules/data_dictionary_widget/src/Fields/FieldCallbacks.php index c63edb3512..d0784d0f58 100644 --- a/modules/data_dictionary_widget/src/Fields/FieldCallbacks.php +++ b/modules/data_dictionary_widget/src/Fields/FieldCallbacks.php @@ -40,8 +40,8 @@ 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_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"] ?? []; // 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']); @@ -103,7 +103,7 @@ public static function addSubformCallback(array &$form, FormStateInterface $form $form_state->set('add_new_field', ''); $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"]; + $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); diff --git a/modules/data_dictionary_widget/src/Fields/FieldOperations.php b/modules/data_dictionary_widget/src/Fields/FieldOperations.php index 523f296a63..40875fb8ae 100644 --- a/modules/data_dictionary_widget/src/Fields/FieldOperations.php +++ b/modules/data_dictionary_widget/src/Fields/FieldOperations.php @@ -196,8 +196,9 @@ public static function checkFieldCollection($data_pre, $op) { /** * Set the elements associated with adding a new field. */ - public static function setAddFormState($add_new_field, $element) { + public static function setAddDictionaryFieldFormState($add_new_field, $element) { if ($add_new_field) { + unset($element['dictionary_fields']["edit_buttons"]); $element['dictionary_fields']['field_collection'] = $add_new_field; $element['dictionary_fields']['field_collection']['#access'] = TRUE; $element['dictionary_fields']['add_row_button']['#access'] = FALSE; @@ -207,6 +208,17 @@ public static function setAddFormState($add_new_field, $element) { return $element; } + /** + * Set the elements associated with editing a dictionary field. + */ + public static function editDictionaryFieldFormState($edit_dictionary_field, $element) { + if ($edit_dictionary_field) { + unset($element['dictionary_fields']["edit_buttons"]); + } + + return $element; + } + /** * Create edit and update fields where needed. */ diff --git a/modules/data_dictionary_widget/src/Indexes/IndexFieldAddCreation.php b/modules/data_dictionary_widget/src/Indexes/IndexFieldAddCreation.php index be87b0585a..0e0a65f3e1 100644 --- a/modules/data_dictionary_widget/src/Indexes/IndexFieldAddCreation.php +++ b/modules/data_dictionary_widget/src/Indexes/IndexFieldAddCreation.php @@ -3,12 +3,12 @@ namespace Drupal\data_dictionary_widget\Indexes; /** - * Various operations for creating Data Dictionary Widget add fields. + * Various operations for creating Index fields. */ class IndexFieldAddCreation { /** - * Create add fields for Data Dictionary Widget. + * Create fields for adding an index. */ public static function addIndex() { $add_index['#access'] = FALSE; @@ -16,7 +16,7 @@ public static function addIndex() { '#type' => 'fieldset', '#title' => t('Index'), '#open' => TRUE, - '#prefix' => '
', + '#prefix' => '
', '#suffix' => '
', '#element_validate' => [ ['\Drupal\data_dictionary_widget\Indexes\IndexValidation', 'indexFieldsValidation'] @@ -48,7 +48,7 @@ public static function addIndex() { $add_index['group']['index']['fields'] = [ '#type' => 'fieldset', '#title' => t('Fields'), - '#prefix' => '
', + '#prefix' => '
', '#suffix' => '
', '#markup' => t('
One or more fields included in index. Must be keys from the fields object.
'), '#attributes' => [ @@ -64,10 +64,10 @@ public static function addIndex() { } /** - * Create add fields for Data Dictionary Widget. + * Create fields for adding an index field. */ public static function addIndexFields($current_index_fields) { - $id = "field-json-metadata-dictionary-index-fields-new"; + $id = "field-json-metadata-index-fields-new"; $add_index_fields['#access'] = FALSE; $add_index_fields['group'] = [ '#type' => 'fieldset', diff --git a/modules/data_dictionary_widget/src/Indexes/IndexFieldButtons.php b/modules/data_dictionary_widget/src/Indexes/IndexFieldButtons.php index 419ade0e72..12dd904c84 100644 --- a/modules/data_dictionary_widget/src/Indexes/IndexFieldButtons.php +++ b/modules/data_dictionary_widget/src/Indexes/IndexFieldButtons.php @@ -3,7 +3,7 @@ namespace Drupal\data_dictionary_widget\Indexes; /** - * Various operations for creating Data Dictionary Widget fields. + * Various operations for index widget buttons. */ class IndexFieldButtons { @@ -25,7 +25,7 @@ public static function addIndexFieldButton() { ], '#ajax' => [ 'callback' => '\Drupal\data_dictionary_widget\Indexes\IndexFieldCallbacks::subIndexFormAjax', - 'wrapper' => 'field-json-metadata-dictionary-index-fields', + 'wrapper' => 'field-json-metadata-index-fields', 'effect' => 'fade', ], '#limit_validation_errors' => [], @@ -50,7 +50,7 @@ public static function addIndexButton() { ], '#ajax' => [ 'callback' => '\Drupal\data_dictionary_widget\Indexes\IndexFieldCallbacks::indexFormAjax', - 'wrapper' => 'field-json-metadata-dictionary-index', + 'wrapper' => 'field-json-metadata-index', 'effect' => 'fade', ], '#limit_validation_errors' => [], @@ -61,10 +61,19 @@ public static function addIndexButton() { * Returns the edit buttons. */ public static function editIndexButtons($indexKey) { + if (str_contains($indexKey, 'field')) { + $callback = 'indexEditSubformCallback'; + $id = 'field-json-metadata-index-fields'; + $function = 'subIndexFormAjax'; + } else { + $callback = 'indexEditCallback'; + $id = 'field-json-metadata-index'; + $function = 'indexFormAjax'; + } return [ '#type' => 'image_button', - '#name' => 'edit_index_' . $indexKey, - '#id' => 'edit_index_' . $indexKey, + '#name' => 'edit_' . $indexKey, + '#id' => 'edit_' . $indexKey, '#access' => TRUE, '#op' => 'edit_' . $indexKey, '#src' => 'core/misc/icons/787878/cog.svg', @@ -75,12 +84,12 @@ public static function editIndexButtons($indexKey) { '#submit' => [ [ '\Drupal\data_dictionary_widget\Indexes\IndexFieldCallbacks', - 'indexEditSubformCallback', + $callback, ], ], '#ajax' => [ - 'callback' => '\Drupal\data_dictionary_widget\Indexes\IndexFieldCallbacks::subIndexFormAjax', - 'wrapper' => 'field-json-metadata-dictionary-index-fields', + 'callback' => '\Drupal\data_dictionary_widget\Indexes\IndexFieldCallbacks::' . $function, + 'wrapper' => $id, 'effect' => 'fade', ], '#limit_validation_errors' => [ @@ -96,6 +105,7 @@ public static function submitIndexFieldButton($location, $indexKey) { $callbackClass = $location == 'edit' ? 'indexEditSubformCallback' : 'indexAddSubformCallback'; $op = !empty($indexKey) ? 'update_' . $indexKey : 'add_index_field'; $value = $location == 'edit' ? 'Save' : 'Add '; + $function = $location == 'edit' ? 'subIndexFormAjax' : 'subIndexFormAjax'; $edit_index_button = [ '#type' => 'submit', '#value' => $value, @@ -107,8 +117,8 @@ public static function submitIndexFieldButton($location, $indexKey) { ], ], '#ajax' => [ - 'callback' => 'Drupal\data_dictionary_widget\Indexes\IndexFieldCallbacks::subIndexFormAjax', - 'wrapper' => 'field-json-metadata-dictionary-index-fields', + 'callback' => 'Drupal\data_dictionary_widget\Indexes\IndexFieldCallbacks::' . $function, + 'wrapper' => 'field-json-metadata-index-fields', 'effect' => 'fade', ], '#limit_validation_errors' => [ @@ -151,7 +161,7 @@ public static function submitIndexButton($location, $indexKey) { ], '#ajax' => [ 'callback' => 'Drupal\data_dictionary_widget\Indexes\IndexFieldCallbacks::indexFormAjax', - 'wrapper' => 'field-json-metadata-dictionary-index', + 'wrapper' => 'field-json-metadata-index', 'effect' => 'fade', ], '#limit_validation_errors' => [ @@ -170,7 +180,7 @@ public static function submitIndexButton($location, $indexKey) { * Create Cancel button. */ public static function cancelIndexFieldButton($location, $indexKey, $id) { - $callbackId = ($id === 'field-json-metadata-dictionary-index-fields-new') ? 'subIndexFormExistingFieldAjax' : 'subIndexFormAjax'; + $callbackId = ($id === 'field-json-metadata-index-fields-new') ? 'subIndexFormExistingFieldAjax' : 'subIndexFormAjax'; $callbackClass = $location == 'edit' ? 'indexEditSubformCallback' : 'indexAddSubformCallback'; $op = $location == 'edit' && $indexKey ? 'abort_' . $indexKey : 'cancel_index_field'; $cancel_index_button = [ @@ -217,7 +227,7 @@ public static function cancelIndexButton($location, $indexKey) { ], '#ajax' => [ 'callback' => 'Drupal\data_dictionary_widget\Indexes\IndexFieldCallbacks::indexFormAjax', - 'wrapper' => 'field-json-metadata-dictionary-index', + 'wrapper' => 'field-json-metadata-index', 'effect' => 'fade', ], '#limit_validation_errors' => [], @@ -232,7 +242,7 @@ public static function cancelIndexButton($location, $indexKey) { /** * Create Delete button. */ - public static function deleteIndexButton($indexKey) { + public static function deleteIndexFieldButton($indexKey) { return [ '#type' => 'submit', '#name' => 'index_delete_' . $indexKey, @@ -246,7 +256,31 @@ public static function deleteIndexButton($indexKey) { ], '#ajax' => [ 'callback' => 'Drupal\data_dictionary_widget\Indexes\IndexFieldCallbacks::subIndexFormAjax', - 'wrapper' => 'field-json-metadata-dictionary-index-fields', + 'wrapper' => 'field-json-metadata-index-fields', + 'effect' => 'fade', + ], + '#limit_validation_errors' => [], + ]; + } + + /** + * Create Delete button. + */ + public static function deleteIndexButton($indexKey) { + return [ + '#type' => 'submit', + '#name' => 'index_delete_' . $indexKey, + '#value' => t('Delete index'), + '#op' => 'delete_' . $indexKey, + '#submit' => [ + [ + '\Drupal\data_dictionary_widget\Indexes\IndexFieldCallbacks', + 'indexEditCallback', + ], + ], + '#ajax' => [ + 'callback' => 'Drupal\data_dictionary_widget\Indexes\IndexFieldCallbacks::indexFormAjax', + 'wrapper' => 'field-json-metadata-index', 'effect' => 'fade', ], '#limit_validation_errors' => [], diff --git a/modules/data_dictionary_widget/src/Indexes/IndexFieldCallbacks.php b/modules/data_dictionary_widget/src/Indexes/IndexFieldCallbacks.php index 6966afeee6..2e007a92aa 100644 --- a/modules/data_dictionary_widget/src/Indexes/IndexFieldCallbacks.php +++ b/modules/data_dictionary_widget/src/Indexes/IndexFieldCallbacks.php @@ -5,7 +5,7 @@ use Drupal\Core\Form\FormStateInterface; /** - * Various operations for the Data Dictionary Widget callbacks. + * Various operations for the Index callbacks. */ class IndexFieldCallbacks { /** @@ -14,9 +14,9 @@ class IndexFieldCallbacks { public static function indexAddSubformCallback(array &$form, FormStateInterface $form_state) { $trigger = $form_state->getTriggeringElement(); $op = $trigger['#op']; - $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"]; + $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"] ?? []; if ($current_index_fields) { $form_state->set('current_index_fields', $current_index_fields); @@ -92,7 +92,7 @@ public static function indexAddCallback(array &$form, FormStateInterface $form_s } /** - * Submit callback for the Index Edit button. + * Submit callback for the Index Field Edit button. */ public static function indexEditSubformCallback(array &$form, FormStateInterface $form_state) { $trigger = $form_state->getTriggeringElement(); @@ -121,7 +121,11 @@ public static function indexEditSubformCallback(array &$form, FormStateInterface } - if (str_contains($op, 'edit')) { + if (str_contains($op, 'edit_index_key')) { + $currently_modifying_index_fields[$op_index[4]] = $current_index_fields[$op_index[4]]; + } + + if (str_contains($op, 'edit_index_field')) { $currently_modifying_index_fields[$op_index[4]] = $current_index_fields[$op_index[4]]; } @@ -132,11 +136,72 @@ public static function indexEditSubformCallback(array &$form, FormStateInterface $form_state->setRebuild(); } + /** + * Submit callback for the Index Edit button. + */ + public static function indexEditCallback(array &$form, FormStateInterface $form_state) { + $trigger = $form_state->getTriggeringElement(); + $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"] ?? []; + $op = $trigger['#op']; + $op_index = explode("_", $trigger['#op']); + $currently_modifying_index_fields = $form_state->get('index_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') : []; + + if (str_contains($op, 'abort_index_key')) { + unset($currently_modifying_index[$op_index[3]]); + } + + if (str_contains($op, 'abort_index_field_key')) { + unset($currently_modifying_index_fields[$op_index[4]]); + } + + if (str_contains($op, 'delete_index_key')) { + unset($currently_modifying_index[$op_index[3]]); + unset($current_index[$op_index[3]]); + } + + if (str_contains($op, 'delete_index_field_key')) { + unset($currently_modifying_index_fields[$op_index[4]]); + unset($current_index_fields[$op_index[4]]); + } + + if (str_contains($op, 'update')) { + $update_values = $form_state->getUserInput(); + $current_index[$op_index[3]] = IndexFieldValues::updateIndexValues($op_index[3], $update_values, $current_index); + unset($currently_modifying_index[$op_index[3]]); + //unset($current_index[$op_index[3]]); + ksort($current_index); + } + + if (str_contains($op, 'edit')) { + $currently_modifying_index[$op_index[3]] = $current_index[$op_index[3]]; + } + + $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('index_being_modified', $currently_modifying_index); + $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->setRebuild(); + } + + /** + * Ajax callback to return index fields. + */ + public static function subIndexEditFormAjax(array &$form, FormStateInterface $form_state) { + return $form["field_json_metadata"]["widget"][0]["indexes"]["edit_index"]["index_key_0"]["group"]["fields"]["fields"]; + } + /** * 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]["indexes"]["edit_index"]["index_key_0"]["group"]["fields"]["fields"]; } /** diff --git a/modules/data_dictionary_widget/src/Indexes/IndexFieldCreation.php b/modules/data_dictionary_widget/src/Indexes/IndexFieldCreation.php index 4fae4f57d9..a928ca590b 100644 --- a/modules/data_dictionary_widget/src/Indexes/IndexFieldCreation.php +++ b/modules/data_dictionary_widget/src/Indexes/IndexFieldCreation.php @@ -3,17 +3,17 @@ namespace Drupal\data_dictionary_widget\Indexes; /** - * Various operations for creating Data Dictionary Widget fields. + * Various operations for creating Index fields. */ class IndexFieldCreation { /** - * Create basic widget. + * Create basic index fields fieldset. */ public static function createGeneralIndexFields($element) { $element['indexes']['fields'] = [ '#type' => 'fieldset', '#title' => t('Fields'), - '#prefix' => '
', + '#prefix' => '
', '#suffix' => '
', '#markup' => t('
One or more fields included in index. Must be keys from the fields object.
'), '#required' => TRUE, @@ -23,13 +23,13 @@ public static function createGeneralIndexFields($element) { } /** - * Create basic widget. + * Create basic indexes fieldset. */ public static function createGeneralIndex($element, $current_indexes) { $element['indexes'] = [ '#type' => 'fieldset', '#title' => t('Indexes'), - '#prefix' => '
', + '#prefix' => '
', '#suffix' => '
', '#markup' => t('
Adding indexes to your datastore tables can improve response times from common queries.
'), ]; @@ -63,7 +63,7 @@ public static function createIndexDataRows($current_indexes, $index_data_results '#access' => ((bool) $current_indexes || (bool) $index_data_results), '#type' => 'table', '#header' => ['NAME', 'TYPE', 'FIELDS'], - '#prefix' => '
', + '#prefix' => '
', '#suffix' => '
', '#rows' => $form_state->get('cancel_index') ? $current_indexes : ($index_data_results ?? []), '#tree' => TRUE, diff --git a/modules/data_dictionary_widget/src/Indexes/IndexFieldEditCreation.php b/modules/data_dictionary_widget/src/Indexes/IndexFieldEditCreation.php index 598bc1c4f9..4cd203b928 100644 --- a/modules/data_dictionary_widget/src/Indexes/IndexFieldEditCreation.php +++ b/modules/data_dictionary_widget/src/Indexes/IndexFieldEditCreation.php @@ -3,15 +3,15 @@ namespace Drupal\data_dictionary_widget\Indexes; /** - * Various operations for creating Data Dictionary Widget add fields. + * Various operations for creating edit fields for indexes. */ class IndexFieldEditCreation { /** - * Create edit fields for Data Dictionary Widget. + * Create edit index fields. */ public static function editIndexFields($indexKey, $current_index_fields, $index_fields_being_modified) { - $id = $current_index_fields ? "field-json-metadata-dictionary-index-fields" : "field-json-metadata-dictionary-index-fields-new"; + $id = $current_index_fields ? "field-json-metadata-index-fields" : "field-json-metadata-index-fields-new"; $indexKeyExplode = explode("_", $indexKey); $edit_index_fields['name'] = [ '#name' => 'field_json_metadata[0][indexes][fields][edit_index_fields][' . $indexKeyExplode[3] . '][name]', @@ -28,31 +28,53 @@ public static function editIndexFields($indexKey, $current_index_fields, $index_ '#required' => TRUE, ]; - $edit_index_fields['update_index_field']['actions'] = self::createIndexActionFields($indexKey, $id); + $edit_index_fields['update_index_field']['actions'] = self::createIndexFieldsActionFields($indexKey, $id); return $edit_index_fields; } /** - * Create edit fields for Data Dictionary Widget. + * Create edit index. */ - public static function editIndex($indexKey, $current_index) { - $id = $current_index ? "field-json-metadata-dictionary-index-fields-new" : "field-json-metadata-dictionary-index-fields"; + public static function editIndex($indexKey, $current_index, $index_being_modified, $form_state) { + $id = $current_index ? "field-json-metadata-index-new" : "field-json-metadata-index"; $indexKeyExplode = explode("_", $indexKey); - $edit_index['name'] = [ - '#name' => 'field_json_metadata[0][index][data][' . $indexKeyExplode[3] . '][field_collection][name]', + + $edit_index['description'] = [ + '#name' => "field_json_metadata[0][indexes][edit_index][index_key_" . $indexKeyExplode[2] . "][description]", '#type' => 'textfield', - '#value' => $current_index[$indexKeyExplode[3]]['name'], + '#value' => $current_index[$indexKeyExplode[2]]['description'], '#title' => 'Name', ]; - $edit_index['length'] = [ - '#name' => 'field_json_metadata[0][index][data]['. $indexKeyExplode[3] .'][field_collection][length]', - '#type' => 'number', - '#value' => $current_index[$indexKeyExplode[3]]['length'], - '#title' => 'Length', + $edit_index['type'] = [ + '#name' => "field_json_metadata[0][indexes][edit_index][index_key_" . $indexKeyExplode[2] . "][type]", + '#type' => 'select', + '#description' => t('Index type.'), + '#title' => 'Index Type', + '#default_value' => 'index', + '#op' => 'index_type', + '#required' => TRUE, + '#options' => [ + 'index' => t('index'), + 'fulltext' => t('fulltext'), + ], + '#value' => $current_index[$indexKeyExplode[2]]['type'], ]; - $edit_index['update_index_field']['actions'] = self::createIndexActionFields($indexKey, $id ); + $edit_index['group'] = [ + '#type' => 'fieldset', + '#title' => t('Fields'), + '#prefix' => '
', + '#suffix' => '
', + '#markup' => t('
One or more fields included in index. Must be keys from the fields object.
'), + '#attributes' => [ + 'class' => ['index-fields-form'], + ], + ]; + + $edit_index['group']['fields']['data'] = IndexFieldCreation::createIndexFieldsDataRows($current_index[$indexKeyExplode[2]]['fields'], $current_index[$indexKeyExplode[2]]['fields'], $current_index[$indexKeyExplode[2]]['fields'], $form_state); + + $edit_index['update_index']['actions'] = self::createIndexActionFields($indexKey, $id ); return $edit_index; } @@ -61,11 +83,23 @@ public static function editIndex($indexKey, $current_index) { * Create Action buttons. */ private static function createIndexActionFields($indexKey, $id) { + return [ + '#type' => 'actions', + 'save_update' => IndexFieldButtons::submitIndexButton('edit', $indexKey), + 'cancel_updates' => IndexFieldButtons::cancelIndexButton('edit', $indexKey, $id), + 'delete_index' => IndexFieldButtons::deleteIndexButton($indexKey), + ]; + } + + /** + * Create Action buttons. + */ + private static function createIndexFieldsActionFields($indexKey, $id) { return [ '#type' => 'actions', 'save_update' => IndexFieldButtons::submitIndexFieldButton('edit', $indexKey), - 'cancel_updates' => IndexFieldButtons::cancelIndexFieldButton('edit', $indexKey, $id), - 'delete_field' => IndexFieldButtons::deleteIndexButton($indexKey), + 'cancel_updates' => IndexFieldButtons::cancelIndexButton('edit', $indexKey, $id), + 'delete_field' => IndexFieldButtons::deleteIndexFieldButton($indexKey), ]; } diff --git a/modules/data_dictionary_widget/src/Indexes/IndexFieldOperations.php b/modules/data_dictionary_widget/src/Indexes/IndexFieldOperations.php index 381472dbbb..e6529c669d 100644 --- a/modules/data_dictionary_widget/src/Indexes/IndexFieldOperations.php +++ b/modules/data_dictionary_widget/src/Indexes/IndexFieldOperations.php @@ -3,62 +3,89 @@ namespace Drupal\data_dictionary_widget\Indexes; /** - * Various operations for the Data Dictionary Widget. + * Various operations for structuring indexes and fields before rendering. */ class IndexFieldOperations { /** - * Setting ajax elements. + * Setting ajax elements when editing newly added index fields. */ - public static function setIndexFieldsAjaxElements(array $dictionaryIndexFields) { - if ($dictionaryIndexFields["data"]) { - foreach ($dictionaryIndexFields['data']['#rows'] as $row => $data) { - $edit_index_button = $dictionaryIndexFields['edit_index_buttons']['index_field_key_' . $row] ?? NULL; - $edit_index_fields = $dictionaryIndexFields['edit_index_fields']['index_field_key_' . $row] ?? NULL; + public static function setIndexFieldsAjaxElementsOnAdd(array $indexFields) { + if ($indexFields["data"]) { + foreach ($indexFields['data']['#rows'] as $row => $data) { + $edit_index_button = $indexFields['edit_index_buttons']['index_field_key_' . $row] ?? NULL; + $edit_index_fields = $indexFields['edit_index_fields']['index_field_key_' . $row] ?? NULL; // Setting the ajax fields if they exsist. if ($edit_index_button) { - $dictionaryIndexFields['data']['#rows'][$row] = array_merge($data, $edit_index_button); - unset($dictionaryIndexFields['edit_index_buttons']['index_field_key_' . $row]); + $indexFields['data']['#rows'][$row] = array_merge($data, $edit_index_button); + unset($indexFields['edit_index_buttons']['index_field_key_' . $row]); } elseif ($edit_index_fields) { - unset($dictionaryIndexFields['data']['#rows']['index_field_key_' . $row]); - $dictionaryIndexFields['data']['#rows'][$row]['field_collection'] = $edit_index_fields; + unset($indexFields['data']['#rows']['index_field_key_' . $row]); + $indexFields['data']['#rows'][$row]['field_collection'] = $edit_index_fields; // Remove the buttons so they don't show up twice. - unset($dictionaryIndexFields['edit_index_fields']['index_field_key_' . $row]); - ksort($dictionaryIndexFields['data']['#rows']); + unset($indexFields['edit_index_fields']['index_field_key_' . $row]); + ksort($indexFields['data']['#rows']); } } } - return $dictionaryIndexFields; + return $indexFields; } /** - * Setting ajax elements. + * Setting ajax elements when editing existing index fields. */ - public static function setIndexAjaxElements(array $dictionaryIndexes) { - foreach ($dictionaryIndexes['data']['#rows'] as $row => $data) { - $edit_index_button = $dictionaryIndexes['edit_index_buttons']['index_key_' . $row] ?? NULL; - $edit_index_fields = $dictionaryIndexes['edit_index_fields']['index_key_' . $row] ?? NULL; + public static function setIndexFieldsAjaxElements(array $indexFields) { + if ($indexFields["data"]) { + foreach ($indexFields['data']['#rows'] as $row => $data) { + $edit_index_fields_button = $indexFields['fields']['edit_index_fields_buttons']['index_field_key_' . $row] ?? NULL; + $edit_index_fields = $indexFields['fields']['edit_index_fields']['index_field_key_' . $row] ?? NULL; + // Setting the ajax fields if they exsist. + if ($edit_index_fields_button) { + //$indexFields["data"]["#rows"][0] = array_merge($data, $edit_index_fields_button); + $indexFields["data"]["#rows"][$row] = array_merge($data, $edit_index_fields_button); + unset($indexFields["fields"]["edit_index_fields_buttons"]['index_field_key_' . $row]); + } + elseif ($edit_index_fields) { + unset($indexFields['data']['#rows']['index_field_key_' . $row]); + $indexFields['data']['#rows'][$row]['field_collection'] = $edit_index_fields; + // Remove the buttons so they don't show up twice. + unset($indexFields['edit_index_fields']['index_field_key_' . $row]); + ksort($indexFields['data']['#rows']); + } + } + } + + return $indexFields; + } + + /** + * Setting index ajax elements. + */ + public static function setIndexAjaxElements(array $indexes) { + foreach ($indexes['data']['#rows'] as $row => $data) { + $edit_index_button = $indexes['edit_index_buttons']['index_key_' . $row] ?? NULL; + $edit_index = $indexes['edit_index']['index_key_' . $row] ?? NULL; // Setting the ajax fields if they exsist. if ($edit_index_button) { - $dictionaryIndexes['data']['#rows'][$row] = array_merge($data, $edit_index_button); - unset($dictionaryIndexes['edit_index_buttons']['index_key_' . $row]); + $indexes['data']['#rows'][$row] = array_merge($data, $edit_index_button); + unset($indexes['edit_index_buttons']['index_key_' . $row]); } - elseif ($edit_index_fields) { - unset($dictionaryIndexes['data']['#rows']['index_key_' . $row]); - $dictionaryIndexes['data']['#rows'][$row]['field_collection'] = $edit_index_fields; + elseif ($edit_index) { + unset($indexes['data']['#rows']['index_key_' . $row]); + $indexes['data']['#rows'][$row]['field_collection'] = $edit_index; // Remove the buttons so they don't show up twice. - unset($dictionaryIndexes['edit_index_fields']['index_key_' . $row]); - ksort($dictionaryIndexes['data']['#rows']); + unset($indexes['edit_index']['index_key_' . $row]); + ksort($indexes['data']['#rows']); } } - return $dictionaryIndexes; + return $indexes; } /** - * Cleaning the data up. + * Prepare index field data results. */ public static function processIndexFieldsDataResults($index_data_results, $current_index_fields, $index_field_values, $op) { if (isset($current_index_fields)) { @@ -84,7 +111,7 @@ public static function processIndexFieldsDataResults($index_data_results, $curre } /** - * Cleaning the data up. + * Prepare index data results. */ public static function processIndexDataResults($index_results, $current_indexes, $index_values, $index_fields_data_results, $op) { if (isset($current_indexes)) { @@ -124,7 +151,18 @@ public static function editIndexActions() { } /** - * Set the elements associated with adding a new field. + * Set the elements associated with editing an index. + */ + public static function editIndexFormState($edit_index, $element) { + if ($edit_index) { + unset($element["indexes"]["edit_index_buttons"]); + } + + return $element; + } + + /** + * Set the elements associated with adding a new index field. */ public static function setAddIndexFieldFormState($add_new_index_field, $element) { if ($add_new_index_field) { @@ -140,10 +178,11 @@ public static function setAddIndexFieldFormState($add_new_index_field, $element) } /** - * Set the elements associated with adding a new field. + * Set the elements associated with adding a new index */ public static function setAddIndexFormState($add_new_index, $element) { if ($add_new_index) { + unset($element["indexes"]["edit_index_buttons"]); $element['indexes']['field_collection'] = $add_new_index; $element['indexes']['field_collection']['#access'] = TRUE; $element['indexes']['add_row_button']['#access'] = FALSE; @@ -155,9 +194,9 @@ public static function setAddIndexFormState($add_new_index, $element) { } /** - * Create edit and update fields where needed. + * Create edit and update fields for index fields. */ - public static function createDictionaryIndexFieldOptions($op_index, $index_data_results, $index_fields_being_modified, $element) { + public static function createIndexFieldOptions($op_index, $index_data_results, $index_fields_being_modified, $element) { $current_index_fields = $index_data_results ?? NULL; // Creating ajax buttons/fields to be placed in correct location later. foreach ($index_data_results as $indexKey => $data) { @@ -165,6 +204,7 @@ public static function createDictionaryIndexFieldOptions($op_index, $index_data_ $element['edit_index_fields']['index_field_key_' . $indexKey] = IndexFieldEditCreation::editIndexFields('index_field_key_' . $indexKey, $current_index_fields, $index_fields_being_modified); } else { + //$element['edit_index_fields_buttons']['index_field_key_' . $indexKey]['edit_index_fields_button'] = IndexFieldButtons::editIndexButtons('index_field_key_' . $indexKey); $element['edit_index_buttons']['index_field_key_' . $indexKey]['edit_index_button'] = IndexFieldButtons::editIndexButtons('index_field_key_' . $indexKey); } } @@ -174,14 +214,15 @@ public static function createDictionaryIndexFieldOptions($op_index, $index_data_ } /** - * Create edit and update fields where needed. + * Create edit and update fields for indexes. */ - public static function createDictionaryIndexOptions($op_index, $index_data_results, $index_fields_being_modified, $element) { + public static function createIndexOptions($op_index, $index_data_results, $index_being_modified, $index_field_being_modified, $element, $form_state) { $current_indexes = $element['current_index']; + // Creating ajax buttons/fields to be placed in correct location later. foreach ($index_data_results as $indexKey => $data) { - if (self::checkIndexEditingField('index_key_' . $indexKey, $op_index, $index_fields_being_modified)) { - $element['edit_index']['index_key_' . $indexKey] = IndexFieldEditCreation::editIndex('index_key_' . $indexKey, $current_indexes, $index_fields_being_modified); + if (self::checkIndexEditing('index_key_' . $indexKey, $op_index, $index_being_modified)) { + $element['edit_index']['index_key_' . $indexKey] = IndexFieldEditCreation::editIndex('index_key_' . $indexKey, $current_indexes, $index_being_modified, $form_state); } else { $element['edit_index_buttons']['index_key_' . $indexKey]['edit_index_button'] = IndexFieldButtons::editIndexButtons('index_key_' . $indexKey); @@ -193,7 +234,7 @@ public static function createDictionaryIndexOptions($op_index, $index_data_resul } /** - * Return true if field is being edited. + * Return true if index field is being edited. */ public static function checkIndexEditingField($indexKey, $op_index, $index_fields_being_modified) { $action_list = IndexFieldOperations::editIndexActions(); @@ -205,4 +246,22 @@ public static function checkIndexEditingField($indexKey, $op_index, $index_field return FALSE; } } + + /** + * Return true if index is being edited. + */ + public static function checkIndexEditing($indexKey, $op_index, $index_being_modified) { + if (isset($op_index)) { + $op_index_string = implode('_', $op_index); + if (str_contains($op_index_string, 'edit_index_key')) { + $action_list = IndexFieldOperations::editIndexActions(); + $indexKeyExplode = explode("_", $indexKey); + if (isset($op_index[0]) && in_array($op_index[0], $action_list) && array_key_exists($indexKeyExplode[2], $index_being_modified)) { + return TRUE; + } + } + } + + return FALSE; + } } \ No newline at end of file diff --git a/modules/data_dictionary_widget/src/Indexes/IndexFieldValues.php b/modules/data_dictionary_widget/src/Indexes/IndexFieldValues.php index 4a5dcac5e8..66cb7840c6 100644 --- a/modules/data_dictionary_widget/src/Indexes/IndexFieldValues.php +++ b/modules/data_dictionary_widget/src/Indexes/IndexFieldValues.php @@ -3,7 +3,7 @@ namespace Drupal\data_dictionary_widget\Indexes; /** - * Various operations for creating index fields. + * Various operations for returning index values when editing the field. */ class IndexFieldValues { /** @@ -18,4 +18,19 @@ public static function updateIndexFieldValues($field_index, $update_values, $cur 'length' => (int)$length, ]; } + + /** + * Return updated index values after edit. + */ + public static function updateIndexValues($field_index, $update_values, $current_index) { + $description = $update_values["field_json_metadata"][0]["indexes"]["edit_index"]['index_key_' . $field_index]["description"]; + $type = $update_values["field_json_metadata"][0]["indexes"]["edit_index"]['index_key_' . $field_index]["type"]; + $fields = $current_index[$field_index]["fields"]; + + return [ + 'description' => $description, + 'type' => $type, + 'fields' => $fields, + ]; + } } diff --git a/modules/data_dictionary_widget/src/Plugin/Field/FieldWidget/DataDictionaryWidget.php b/modules/data_dictionary_widget/src/Plugin/Field/FieldWidget/DataDictionaryWidget.php index c5ac9577f8..8fc0837e3a 100644 --- a/modules/data_dictionary_widget/src/Plugin/Field/FieldWidget/DataDictionaryWidget.php +++ b/modules/data_dictionary_widget/src/Plugin/Field/FieldWidget/DataDictionaryWidget.php @@ -30,59 +30,80 @@ class DataDictionaryWidget extends WidgetBase implements TrustedCallbackInterfac * {@inheritdoc} */ public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) { - // Retrieve values from form state + // Retrieve data-dictionary form_state values to be used for various operations. $dictionary_field_values = $form_state->get("new_dictionary_fields"); - $index_values = $form_state->get('new_index'); - $index_field_values = $form_state->get("new_index_fields"); - $add_index_field = $form_state->get('add_new_index_field'); - $add_new_index = $form_state->get('add_new_index'); $add_new_dictionary_field = $form_state->get('add_new_field'); $current_dictionary_fields = $form_state->get('current_dictionary_fields'); + $dictionary_fields_being_modified = $form_state->get("dictionary_fields_being_modified") ?? NULL; + + // Retrieve indexes form_state values to be used for various operations. $current_indexes = $form_state->get('current_index'); + $index_values = $form_state->get('new_index'); + $add_new_index = $form_state->get('add_new_index'); + $index_being_modified = $form_state->get("index_being_modified") ?? NULL; + + // Retrieve index fields form_state values to be used for various operations. $current_index_fields = $form_state->get('current_index_fields'); - $dictionary_fields_being_modified = $form_state->get("dictionary_fields_being_modified") ?? NULL; + $index_field_values = $form_state->get("new_index_fields"); + $add_index_field = $form_state->get('add_new_index_field'); $index_fields_being_modified = $form_state->get("index_fields_being_modified") ?? NULL; + // Retrieve triggered element to be used for various operations. $op = $form_state->getTriggeringElement()['#op'] ?? NULL; + $op_index = isset($op) ? explode("_", $op) : NULL; + + // Retrieve form element item values. $field_json_metadata = !empty($items[0]->value) ? json_decode($items[0]->value, TRUE) : []; - $op_index = isset($form_state->getTriggeringElement()['#op']) ? explode("_", $form_state->getTriggeringElement()['#op']) : NULL; - // Retrieve initial data results from field JSON metadata + // Retrieve initial data results from field JSON metadata. $data_results = $field_json_metadata["data"]["fields"] ?? []; $index_fields_results = $field_json_metadata["data"]["indexes"][0]["fields"] ?? []; $index_results = $field_json_metadata["data"]["indexes"] ?? []; - // Process data results + // Process data results. $data_results = FieldOperations::processDataResults($data_results, $current_dictionary_fields, $dictionary_field_values, $op); $index_fields_data_results = IndexFieldOperations::processIndexFieldsDataResults($index_fields_results, $current_index_fields, $index_field_values, $op); $index_data_results = IndexFieldOperations::processIndexDataResults($index_results, $current_indexes, $index_values, $index_fields_data_results, $op); - // Create form elements + // Create form elements. $element = FieldCreation::createGeneralFields($element, $field_json_metadata, $current_dictionary_fields, $form_state); $element = IndexFieldCreation::createGeneralIndex($element, $current_indexes); - $element = IndexFieldCreation::createGeneralIndexFields($element); + if ($index_field_values || $add_index_field || $index_fields_being_modified) { + $element = IndexFieldCreation::createGeneralIndexFields($element); + } - // Add pre-render functions + // Add pre-render functions. $element['dictionary_fields']['#pre_render'] = [[$this, 'preRenderForm']]; $element['indexes']['#pre_render'] = [[$this, 'preRenderIndexForm']]; - $element['indexes']['fields']['#pre_render'] = [[$this, 'preRenderIndexFieldForm']]; + $element['indexes']['fields']['#pre_render'] = [[$this, 'preRenderIndexFieldFormOnAdd']]; - // Add data rows to display in tables + // Add data rows to display in tables. $element['dictionary_fields']['data'] = FieldCreation::createDictionaryDataRows($current_dictionary_fields, $data_results, $form_state); $element['indexes']['data'] = IndexFieldCreation::createIndexDataRows($current_indexes, $index_data_results, $form_state); $element['indexes']['fields']['data'] = IndexFieldCreation::createIndexFieldsDataRows($index_field_values, $current_index_fields, $index_fields_data_results, $form_state); - // Create dictionary fields/buttons for editing + // Create dictionary fields/buttons for editing. $element['dictionary_fields'] = FieldOperations::createDictionaryFieldOptions($op_index, $data_results, $dictionary_fields_being_modified, $element['dictionary_fields']); $element['dictionary_fields']['add_row_button']['#access'] = $dictionary_fields_being_modified == NULL ? TRUE : FALSE; - // Create index fields/buttons for editing - $element['indexes'] = IndexFieldOperations::createDictionaryIndexOptions($op_index, $index_data_results, $index_fields_being_modified, $element['indexes']); + // Create index fields/buttons for editing. + $element['indexes'] = IndexFieldOperations::createIndexOptions($op_index, $index_data_results, $index_being_modified, $index_fields_being_modified, $element['indexes'], $form_state); + //$element['indexes'] = IndexFieldOperations::createIndexOptions($op_index, $index_data_results, $index_fields_being_modified, $element['indexes'], $form_state); + + // Create edit buttons and fields for index fields. if ($index_field_values || $current_index_fields) { - $element["indexes"]["fields"] = IndexFieldOperations::createDictionaryIndexFieldOptions($op_index, $index_fields_data_results, $index_fields_being_modified, $element['indexes']['fields']); + $element["indexes"]["fields"] = IndexFieldOperations::createIndexFieldOptions($op_index, $index_fields_data_results, $index_fields_being_modified, $element['indexes']['fields']); } - $element['indexes']['fields']['add_row_button']['#access'] = $index_fields_being_modified == NULL ? TRUE : FALSE; - + + // Set access to index fields Add button when index fields being modified. + $element['indexes']['add_row_button']['#access'] = $index_being_modified == NULL ? TRUE : FALSE; + + // if ($index_field_values || $current_index_fields || $index_being_modified || $index_fields_being_modified) { + // $element["indexes"]["edit_index"]["index_key_0"]["group"]["fields"]["fields"] = IndexFieldOperations::createDictionaryIndexFieldOptions($op_index, $index_fields_data_results, $index_fields_being_modified, $element['indexes']['fields']); + // $element["indexes"]["edit_index"]["index_key_0"]["group"]["fields"]['#pre_render'] = [[$this, 'preRenderIndexFieldForm']]; + // //$element["indexes"]['edit_index_fields']["index_field_key_0"]['#pre_render'] = [[$this, 'preRenderIndexFieldForm']]; + // } + // Get form entity $form_object = $form_state->getFormObject(); if (!($form_object instanceof EntityFormInterface)) { @@ -96,9 +117,11 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen } // Set form state for adding fields and indexes - $element = FieldOperations::setAddFormState($add_new_dictionary_field, $element); + $element = FieldOperations::setAddDictionaryFieldFormState($add_new_dictionary_field, $element); + $element = FieldOperations::editDictionaryFieldFormState($dictionary_fields_being_modified, $element); $element = IndexFieldOperations::setAddIndexFormState($add_new_index, $element); $element = IndexFieldOperations::setAddIndexFieldFormState($add_index_field, $element); + $element = IndexFieldOperations::editIndexFormState($index_being_modified, $element); // Display index fields only when new index fields are being created. if ($add_index_field || $index_field_values) { @@ -114,42 +137,40 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen * {@inheritdoc} */ public function massageFormValues(array $values, array $form, FormStateInterface $form_state) { - $current_dictionary_fields = $form["field_json_metadata"]["widget"][0]["dictionary_fields"]["data"]["#rows"]; - $current_indexes = $form["field_json_metadata"]["widget"][0]["indexes"]["data"]["#rows"]; + $current_dictionary_fields = $form["field_json_metadata"]["widget"][0]["dictionary_fields"]["data"]["#rows"] ?? []; + $current_indexes = $form["field_json_metadata"]["widget"][0]["indexes"]["data"]["#rows"] ?? []; $field_collection = $values[0]['dictionary_fields']["field_collection"]["group"] ?? []; $indexes_collection = $values[0]["indexes"]["fields"]["field_collection"]["group"] ?? []; - $fields_input = !empty($field_collection) ? [ + if (!empty($indexes_collection) && !empty($indexes_collection["indexes"]["fields"])) { + $index_fields = $indexes_collection["indexes"]["fields"]; + } + + $dictionary_fields_input = !empty($field_collection) ? [ [ - "name" => $field_collection["name"], - "title" => $field_collection["title"], - "type" => $field_collection["type"], - "format" => $field_collection["format"], - "description" => $field_collection["description"], + "name" => $field_collection["name"] ?? '', + "title" => $field_collection["title"] ?? '', + "type" => $field_collection["type"] ?? '', + "format" => $field_collection["format"] ?? '', + "description" => $field_collection["description"] ?? '', ], ] : []; $index_inputs = !empty($indexes_collection) ? [ [ - "name" => $indexes_collection["indexes"]["fields"]["name"], - "length" => (int)$indexes_collection["indexes"]["fields"]["length"], + "name" => $index_fields["name"] ?? '', + "length" => isset($index_fields["length"]) ? (int)$index_fields["length"] : 0, ], ] : []; - if (isset($fields_input)) { - $fields = array_merge($current_dictionary_fields ?? [], $fields_input); - } - else { - $fields = $current_dictionary_fields ?? []; - } - + $dictionary_fields = array_merge($current_dictionary_fields ?? [], $dictionary_fields_input); $indexes = array_merge($current_indexes ?? [], $index_inputs); $json_data = [ 'identifier' => $values[0]['identifier'] ?? '', 'data' => [ 'title' => $values[0]['title'] ?? '', - 'fields' => $fields, + 'fields' => $dictionary_fields, 'indexes' => $indexes, ], ]; @@ -175,6 +196,15 @@ public function preRenderIndexFieldForm(array $indexFields) { return IndexFieldOperations::setIndexFieldsAjaxElements($indexFields); } + /** + * Prerender callback for the index field form. + * + * Moves the buttons into the table. + */ + public function preRenderIndexFieldFormOnAdd(array $indexFields) { + return IndexFieldOperations::setIndexFieldsAjaxElementsOnAdd($indexFields); + } + /** * Prerender callback for the index form. * @@ -188,7 +218,7 @@ public function preRenderIndexForm(array $indexes) { * {@inheritdoc} */ public static function trustedCallbacks() { - return ['preRenderForm', 'preRenderIndexFieldForm', 'preRenderIndexForm']; + return ['preRenderForm', 'preRenderIndexFieldFormOnAdd', 'preRenderIndexFieldForm', 'preRenderIndexForm']; } } diff --git a/modules/data_dictionary_widget/templates/custom-index-fields-table.html.twig b/modules/data_dictionary_widget/templates/custom-index-fields-table.html.twig index 1b401daf01..436a40437a 100644 --- a/modules/data_dictionary_widget/templates/custom-index-fields-table.html.twig +++ b/modules/data_dictionary_widget/templates/custom-index-fields-table.html.twig @@ -6,7 +6,7 @@ {{ header[2] }} - + {% for row in rows %} {% if row.field_collection %} @@ -20,6 +20,7 @@ {{ row.length }} {{ row.edit_index_button }} + {# {{ row.edit_index_fields_button }} #} {% endif %} diff --git a/modules/data_dictionary_widget/templates/custom-index-table.html.twig b/modules/data_dictionary_widget/templates/custom-index-table.html.twig index fe13096e3f..7248bdbeca 100644 --- a/modules/data_dictionary_widget/templates/custom-index-table.html.twig +++ b/modules/data_dictionary_widget/templates/custom-index-table.html.twig @@ -6,7 +6,7 @@ {{ header[2] }} - + {% for row in rows %} {% if row.field_collection %} diff --git a/modules/data_dictionary_widget/tests/src/Unit/DataDictionaryWidgetBuildTest.php b/modules/data_dictionary_widget/tests/src/Unit/DataDictionaryWidgetBuildTest.php index 387c07818d..9e50495603 100644 --- a/modules/data_dictionary_widget/tests/src/Unit/DataDictionaryWidgetBuildTest.php +++ b/modules/data_dictionary_widget/tests/src/Unit/DataDictionaryWidgetBuildTest.php @@ -112,7 +112,7 @@ public function testFieldCollectionDictionaryWidget() { $add_fields = FieldAddCreation::addFields(); - $element = FieldOperations::setAddFormState($add_fields, $element); + $element = FieldOperations::setAddDictionaryFieldFormState($add_fields, $element); $this->assertNotNull($element); $this->assertNotNull($element["dictionary_fields"]["field_collection"]); @@ -238,7 +238,7 @@ public function testAddNewFieldDictionaryWidget() { $add_fields = FieldAddCreation::addFields(); - $element = FieldOperations::setAddFormState($add_fields, $element); + $element = FieldOperations::setAddDictionaryFieldFormState($add_fields, $element); // Set up a triggering element with '#op' set to 'add'. $trigger = ['#op' => 'add']; @@ -320,9 +320,9 @@ public function testEditButtonsCreation() { ->method('set') ->with('field_data_type', 'data-dictionary'); - $formState->expects($this->exactly(13)) + $formState->expects($this->exactly(14)) ->method('get') - ->willReturnOnConsecutiveCalls(NULL, NULL, NULL, FALSE, NULL, NULL, $current_fields); + ->willReturnOnConsecutiveCalls(NULL, NULL, $current_fields, FALSE, NULL, NULL, NULL); $dataDictionaryWidget = new DataDictionaryWidget ( $plugin_id, @@ -472,15 +472,41 @@ public function testEditDataDictionaryField() { $formState->expects($this->any()) ->method('get') ->willReturnOnConsecutiveCalls( - [], [], $user_input, [], [], [], [], [], $current_dictionary_fields, [], [], $current_dictionary_fields, [], - [], [], $user_input, [], [], [], [], [], [], [], [], $updated_dictionary_fields, [], [], $current_dictionary_fields, [], + [], + $current_dictionary_fields, + [], + [], + [], + $current_dictionary_fields, + [], + [], + [], + [], + [], + [], + [], + [], + [], + $user_input, + [], + $current_dictionary_fields, + [], + [], + [], + [], + $updated_dictionary_fields, + [], + [], + [], + [], + [] ); $formState->expects($this->any()) ->method('getTriggeringElement') ->willReturnOnConsecutiveCalls( - ['#op' => $op], ['#op' => $op], ['#op' => $op], ['#op' => $op], ['#op' => $op], ['#op' => $op], ['#op' => $op], ['#op' => $op], ['#op' => $op], ['#op' => $op], - ['#op' => 'update_0'], ['#op' => 'update_0'], ['#op' => 'update_0'], ['#op' => 'update_0'], ['#op' => 'update_0'], ['#op' => 'update_0'], ['#op' => 'update_0'], ['#op' => 'update_0'], ['#op' => 'update_0'], ['#op' => 'update_0'], + ['#op' => $op], ['#op' => $op], ['#op' => $op], ['#op' => $op], ['#op' => $op], ['#op' => $op], + ['#op' => 'update_0'], ['#op' => 'update_0'], ['#op' => 'update_0'], ['#op' => 'update_0'], ['#op' => 'update_0'], ); $formState->expects($this->any())