Skip to content

Commit

Permalink
UHF-9739: UHF-9739: Added updating news auto toggle javascript library.
Browse files Browse the repository at this point in the history
  • Loading branch information
khalima committed May 3, 2024
1 parent 96f2933 commit 85c211e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 3 deletions.
1 change: 1 addition & 0 deletions dist/js/updatingNewsAutoToggle.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions hdbt_admin.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ tpr-edit-form:
js:
dist/js/tprEditForm.min.js: {}

updating-news-auto-toggle:
js:
dist/js/updatingNewsAutoToggle.min.js: {}
version: 1.0
dependencies:
- core/once

debug-item-composer:
js:
dist/js/debug-item-composer.min.js: {}
Expand Down
5 changes: 5 additions & 0 deletions hdbt_admin.theme
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ function hdbt_admin_form_node_form_alter(&$form, FormStateInterface $form_state)
) {
$form['menu']['content_translation_status']['#access'] = FALSE;
}

// Auto toggle updating news field group if there is content in the group.
if ($node->getType() === 'news_item') {
$form['#attached']['library'][] = 'hdbt_admin/updating-news-auto-toggle';
}
}

/**
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions src/js/updatingNewsAutoToggle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @file
* Updating news field group auto toggle if there is content.
*/

(function (once) {

'use strict';

const updatingNews = once(
'updating-news-auto-toggle',
'[data-drupal-selector="edit-group-updating-news"]'
);

if (updatingNews.length === 0) {
return;
}

updatingNews.forEach(details => {
const updatingNewsContent = details.querySelector(
'table.field-news-item-updating-news-values > tbody'
);

if (updatingNewsContent) {
details.open = true;
}
});
})(once);

0 comments on commit 85c211e

Please sign in to comment.