diff --git a/dist/js/updatingNewsAutoToggle.min.js b/dist/js/updatingNewsAutoToggle.min.js new file mode 100644 index 00000000..e8f2ddb6 --- /dev/null +++ b/dist/js/updatingNewsAutoToggle.min.js @@ -0,0 +1 @@ +!function(e){"use strict";const t=e("updating-news-auto-toggle",'[data-drupal-selector="edit-group-updating-news"]');0!==t.length&&t.forEach((e=>{e.querySelector("table.field-news-item-updating-news-values > tbody")&&(e.open=!0)}))}(once); \ No newline at end of file diff --git a/hdbt_admin.libraries.yml b/hdbt_admin.libraries.yml index b4c7ce10..ff962719 100644 --- a/hdbt_admin.libraries.yml +++ b/hdbt_admin.libraries.yml @@ -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: {} diff --git a/hdbt_admin.theme b/hdbt_admin.theme index 499300ac..91a22a42 100644 --- a/hdbt_admin.theme +++ b/hdbt_admin.theme @@ -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'; + } } /** diff --git a/package-lock.json b/package-lock.json index bacb329a..aadfd143 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3643,9 +3643,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001607", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001607.tgz", - "integrity": "sha512-WcvhVRjXLKFB/kmOFVwELtMxyhq3iM/MvmXcyCe2PNf166c39mptscOc/45TTS96n2gpNV2z7+NakArTWZCQ3w==", + "version": "1.0.30001615", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001615.tgz", + "integrity": "sha512-1IpazM5G3r38meiae0bHRnPhz+CBQ3ZLqbQMtrg+AsTPKAXgW38JNsXkyZ+v8waCsDmPq87lmfun5Q2AGysNEQ==", "funding": [ { "type": "opencollective", diff --git a/src/js/updatingNewsAutoToggle.js b/src/js/updatingNewsAutoToggle.js new file mode 100644 index 00000000..8d9d7db5 --- /dev/null +++ b/src/js/updatingNewsAutoToggle.js @@ -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);