From 5d602c794d7192faf83ca43173f76e561bb445c7 Mon Sep 17 00:00:00 2001 From: sgrichards Date: Fri, 27 Sep 2024 13:24:48 +0100 Subject: [PATCH 1/2] ACO-3646 | utilising this module to improve local development velocity by overriding app.js library when cohesion-dev is available --- cohesion_devel.module | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/cohesion_devel.module b/cohesion_devel.module index 74574ff..46502cb 100644 --- a/cohesion_devel.module +++ b/cohesion_devel.module @@ -30,3 +30,25 @@ function cohesion_devel_page_attachments(array &$attachments) { } } + +/** + * Implements hook_library_info_alter(). + * + * @param $libraries + * @param $extension + * @return void + */ +function cohesion_devel_library_info_alter(&$libraries, $extension) { + $cohesion_dev_path = 'cohesion-services/dx8-gateway/assets/dx8/scripts/app.js'; + if ( + isset($libraries['cohesion-admin-scripts']) && + file_exists(\Drupal::service('extension.path.resolver')->getPath('module', 'cohesion') . '/' . $cohesion_dev_path)) { + + // Get relative path from stream wrapper. + $path = \Drupal::service('file_url_generator')->generateString('public://cohesion/scripts/dx8/app.js'); + + // Load the app.js directly from the cohesion-services directory. + $app_js_library = array_shift($libraries['cohesion-admin-scripts']['js'][$path]); + $libraries['cohesion-admin-scripts']['js'][$cohesion_dev_path] = $app_js_library; + } +} From 9814a955abe7bf0031c9850f38a9ffb29f165ae8 Mon Sep 17 00:00:00 2001 From: sgrichards Date: Fri, 27 Sep 2024 16:04:07 +0100 Subject: [PATCH 2/2] ACO-3646 - fixes --- cohesion_devel.module | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cohesion_devel.module b/cohesion_devel.module index 46502cb..76ec3ce 100644 --- a/cohesion_devel.module +++ b/cohesion_devel.module @@ -48,7 +48,8 @@ function cohesion_devel_library_info_alter(&$libraries, $extension) { $path = \Drupal::service('file_url_generator')->generateString('public://cohesion/scripts/dx8/app.js'); // Load the app.js directly from the cohesion-services directory. - $app_js_library = array_shift($libraries['cohesion-admin-scripts']['js'][$path]); - $libraries['cohesion-admin-scripts']['js'][$cohesion_dev_path] = $app_js_library; + unset($libraries['cohesion-admin-scripts']['js'][$path]); + $libraries['cohesion-admin-scripts']['js'][$cohesion_dev_path] = ['minified' => true]; + } }