Liferay DXP contains several default YUI/AUI modules. You may need to override functionality provided by these module’s scripts. It’s possible to override JSPs using fragments, but you can’t with JavaScript files. Instead, you create a custom AUI module containing three things:
- A copy of the original module’s JavaScript file containing your modifications
- A
config.js
file that specifies the modified JavaScript file’s path and the module it overrides - A
bnd.bnd
file that tells the OSGi container to override the original
Follow these steps:
-
Create an OSGi module to override the original one. For example, you can create a module named
session-js-override-web
to override Liferay DXP’ssession.js
file. -
Create a
src/main/resources/META-INF/resources/js
folder in your module, copy the original JavaScript file into it, and rename it. For example, create a copy of thesession.js
module and rename itsession-override.js
. Make sure you also rename the module definition inside thesession-override.js
, e.g.AUI().add('liferay-session-override', ...
. -
Apply your modifications and save the file.
-
Next, you’ll write your module’s configuration file (
config.js
) to apply your override. Add theconfig.js
file to the module’ssrc/main/resources/META-INF/resources/js
folder. The exampleconfig.js
file below specifies thecondition
that the YUI/AUI Loader should load the custom AUI module (liferay-session-override
)instead
(indicated with thewhen
property) of thetrigger
module (liferay-session
). You can follow this same pattern to create your module’sconfig.js
file:;(function() { var base = MODULE_PATH + '/js/'; AUI().applyConfig( { groups: { mymodulesoverride: { //mymodulesoverride base: base, combine: Liferay.AUI.getCombine(), filter: Liferay.AUI.getFilterConfig(), modules: { 'liferay-session-override': { //my-module-override path: 'session-override.js', //my-module.js condition: { name: 'liferay-session-override', //my-module-override trigger: 'liferay-session', //original module when: 'instead' } } }, root: base } } } ); })();
-
Finally, you must configure your
bnd.bnd
file. For the system to apply the changes, you must specify theconfig.js
’s location with theLiferay-JS-Config
BND header. Theliferay-session-override
module from the previous example has the configuration below in itsbnd.bnd
file:Bundle-Name: session-js-override Bundle-SymbolicName: session.js.override.web Bundle-Version: 1.0.0 Liferay-JS-Config:/META-INF/resources/js/config.js Web-ContextPath: /liferay-session-override-web
Now you know how to override Liferay DXP’s default YUI/AUI modules!