diff --git a/cypress/integration/09_admin_links.spec.js b/cypress/integration/09_admin_links.spec.js index 6fd29be940..4df326c64c 100755 --- a/cypress/integration/09_admin_links.spec.js +++ b/cypress/integration/09_admin_links.spec.js @@ -88,7 +88,7 @@ context('Administration pages', () => { }) cy.contains('h1', 'DKAN Metastore (Data Dictionaries)'); cy.get('.button').contains('+ Add new data dictionary').click( { force:true }) - cy.get('summary').contains('Project Open Data Data-Dictionary'); + cy.get('fieldset').contains('Data Dictionary Fields'); }) }) diff --git a/dkan.install b/dkan.install index dc584e15e1..58e5714538 100644 --- a/dkan.install +++ b/dkan.install @@ -10,4 +10,11 @@ function dkan_update_9001() { $modules = ['path', 'config']; \Drupal::service('module_installer')->install($modules); -} \ No newline at end of file +} + +/** + * Enable data dictionary widget. + */ +function dkan_update_9002() { + \Drupal::service('module_installer')->install(['data_dictionary_widget']); +} diff --git a/modules/data_dictionary_widget/data_dictionary_widget.module b/modules/data_dictionary_widget/data_dictionary_widget.module index b92816f929..c72405135f 100644 --- a/modules/data_dictionary_widget/data_dictionary_widget.module +++ b/modules/data_dictionary_widget/data_dictionary_widget.module @@ -6,8 +6,11 @@ */ use Drupal\Core\Entity\Display\EntityFormDisplayInterface; +use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Url; use Drupal\data_dictionary_widget\Fields\FieldOperations; use Drupal\node\NodeInterface; +use Symfony\Component\HttpFoundation\RedirectResponse; /** * Implements hook_theme(). @@ -65,20 +68,31 @@ function data_dictionary_widget__data_dictionary_data_type_checker($context) { * Implements hook_form_alter(). * * Setting form validation for unique identifier. - * + * * Modifying current_fields array structure to prevent errors in element render array. - * + * * Attaching module library to render theme changes. */ function data_dictionary_widget_form_alter(&$form, &$form_state, $form_id) { $formObject = $form_state->getFormObject(); + if ($formObject instanceof \Drupal\Core\Entity\EntityFormInterface) { $entity = $formObject->getEntity(); + $data_type = $entity->get('field_data_type')->value; if (isset($form["field_json_metadata"]["widget"][0]["dictionary_fields"])) { if ($entity->getEntityTypeId() === 'node' && in_array($entity->bundle(), ['data'])) { $form['#attached']['library'][] = 'data_dictionary_widget/dataDictionaryWidget'; } } + + // If we are saving a data dictionary alter the submit. + foreach (array_keys($form['actions']) as $action) { + if ( isset($form['actions'][$action]['#type']) + && $form['actions'][$action]['#type'] === 'submit' + && $data_type == 'data-dictionary') { + $form['actions']['submit']['#submit'][] = 'data_dictionary_widget_form_submit'; + } + } } if ($form_id == 'node_data_edit_form' || $form_id == 'node_data_form') { @@ -90,7 +104,7 @@ function data_dictionary_widget_form_alter(&$form, &$form_state, $form_id) { foreach ($current_fields as $key => $value) { $keys = array_keys($value); $formatted_current_fields[$key] = []; - + foreach ($keys as $attr) { $formatted_current_fields[$key][$attr] = [ '#value' => $value[$attr] @@ -110,6 +124,16 @@ function data_dictionary_widget_form_alter(&$form, &$form_state, $form_id) { } } +/** + * Redirect to the data dictionary view after saving a data dictionary. + */ +function data_dictionary_widget_form_submit($form, FormStateInterface $form_state) { + $url = Url::fromRoute('metastore.data_dictionary'); + $response = new RedirectResponse($url->toString()); + $response->send(); + return; +} + /** * Checking if identifier is already used. */ @@ -120,7 +144,7 @@ function data_dictionary_widget_validate_unique_identifier($form, &$form_state) if (isset($form["field_json_metadata"]["widget"][0]["identifier"]["#value"])) { $submitted_identifier = $form["field_json_metadata"]["widget"][0]["identifier"]["#value"]; - + foreach ($existing_data_dictionary_nodes as $node) { if ($current_nid !== $node["nid"] && strtolower($submitted_identifier) === strtolower($node["identifier"])) { $form_state->setError($form["field_json_metadata"]["widget"][0]["identifier"], 'The identifier you entered is taken. Please choose another one.'); diff --git a/modules/metastore/metastore.install b/modules/metastore/metastore.install index ed57dece1e..51b303daff 100644 --- a/modules/metastore/metastore.install +++ b/modules/metastore/metastore.install @@ -145,7 +145,7 @@ function metastore_update_8009() { $dict->save(); $count++; } - return t("Updated $count dictionaries. If you have overridden DKAN's core schemas, + return t("Updated $count dictionaries. If you have overridden DKAN's core schemas, you must update your site's data dictionary schema after this update. Copy modules/contrib/dkan/schema/collections/data-dictionary.json over you local site version before attempting to read or write any data dictionaries.");