Skip to content

Commit

Permalink
Set form title based on data node type (#4323)
Browse files Browse the repository at this point in the history
  • Loading branch information
janette authored Oct 30, 2024
1 parent b193c90 commit 5970437
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cypress/integration/08_admin_views.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ context('Admin content and dataset views', () => {
cy.get('#view-field-data-type-table-column > a').should('contain','Data Type');
// There is an "Add new dataset" button that takes user to the dataset json form.
cy.get('.view-header > .form-actions > .button').should('contain', 'Add new dataset').click({ force:true })
cy.contains('h1', 'Create Data');
cy.contains('h1', 'Create dataset');
})

it('User can create a dataset with the UI.', () => {
Expand Down
5 changes: 3 additions & 2 deletions cypress/integration/09_admin_links.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ context('Administration pages', () => {
cy.contains('h1', 'Datasets');

cy.get('.button').contains('+ Add new dataset').click( { force:true })
cy.contains('h1', 'Create Data');
cy.contains('h1', 'Create dataset');
})

it('DKAN menu contains link to create a dataset.', () => {
Expand All @@ -78,7 +78,7 @@ context('Administration pages', () => {
cy.wrap($el).contains('Datasets').parent().within(() => {
cy.get('li.menu-item a').contains('Create').click({ force:true })
})
cy.contains('h1', 'Create Data')
cy.contains('h1', 'Create dataset')
})
})

Expand All @@ -89,6 +89,7 @@ context('Administration pages', () => {
cy.contains('h1', 'DKAN Metastore (Data Dictionaries)');
cy.get('.button').contains('+ Add new data dictionary').click( { force:true })
cy.get('fieldset').contains('Data Dictionary Fields');
cy.contains('h1', 'Create data-dictionary')
})

})
4 changes: 4 additions & 0 deletions modules/metastore/metastore.module
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ function metastore_entity_is_valid_item(EntityInterface $entity) {
* Implements hook_form_alter().
*/
function metastore_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if ($form_id == 'node_data_form') {
$datatype = \Drupal::request()->get('schema') ?? 'dataset';
$form['#title'] = t('Create @datatype', ['@datatype' => $datatype]);
}
$fieldName = \Drupal::service('dkan.metastore.metastore_item_factory')::getMetadataField();
if (isset($form[$fieldName]['widget'][0]['value']['#default_value'])) {
$json = $form[$fieldName]['widget'][0]['value']['#default_value'];
Expand Down

0 comments on commit 5970437

Please sign in to comment.