Featured post

Docker setup for Liferay 7 with MySQL

Thursday 2 November 2017

Override OOTB javascript in Liferay 7 or LIferay DXP

Liferay becomes modular and it requires more efforts to extend it's functionality. I believe that is for our own good but yeah it becomes complex.

To override a javascript file now requires a bundle with some specific entries.
In this example I am overriding logo editor of Liferay and adding a console log to demonstrate the same.

  1. BND
  2. CONFIG.JS
  3. FILE_TO_OVERRIDE
1.BND

Liferay-JS-Config takes the config file which does the magic to override. Even though this file is useful for multiple occasions, for now we will use it for this purpose only.
Web context path for web resources, in our case it's java script.




Bundle-Name: logo-editor-for-snap
Bundle-SymbolicName: logo-editor-for-snap
Bundle-Version: 1.0.0
Liferay-JS-Config: /META-INF/resources/js/config.js
Web-ContextPath: /logo-editor-web-override



2.CONFIG.JS

  • base: File location to override
  • path: File Name
  • condition: In which scenario this module should be loaded
    • name: Name of the module
    • trigger: Should trigger when a call made to module, e.g. liferay-logo-editor
    • when: This module replace triggered module with value instead. There are multiple values possible for this, subject to explore.
;(function() {
    AUI().applyConfig(
        {
            groups: {
                sessionext: {
                    base: MODULE_PATH + '/js/',
                    combine: Liferay.AUI.getCombine(),
                    filter: Liferay.AUI.getFilterConfig(),
                    modules: {
                        'liferay-logo-editor-override': {
                            path: 'liferay-logo_editor.js',
                            condition: {
                                name: 'liferay-logo-editor-override',
                                trigger: 'liferay-logo-editor',
                                when: 'instead'
                            }
                        }
                    },
                    root: MODULE_PATH + '/js/'
                }
            }
        }
    );
})();



3. FILE TO OVERRIDE [e.g. logo_editor.js renamed to liferay-logo_editor.js]

Change the module name at first line.


AUI.add( 'liferay-logo-editor-override', function(A) { var Lang = A.Lang;
....
....
....
renderUI: function() { var instance = this; console.log("LOGO EDITOR OVERRIDDEN...");
....
....


I took the reference from this post and explained as much I can.
Thanks to Liferay Staff members for the snippets!

You are just done, Try & Enjoy the function.............:)


27 comments:

  1. Really cool post, highly informative and professionally written and I am glad to be a visitor of this perfect blog, thank you for this rare info!
    Front end development course in chennai

    ReplyDelete
  2. Thanks for giving a great information about override-javascript Good Explination nice Article
    anyone want to learn advance devops tools or devops online training
    DevOps Online Training DevOps Online Training hyderabadcontact Us: 9704455959

    ReplyDelete
  3. This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to article very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
    DedicatedHosting4u.com

    ReplyDelete
  4. I’d should talk to you here. Which is not some thing I do! I quite like reading a post which will make people believe. Also, many thanks permitting me to comment! webflow agency

    ReplyDelete
  5. Hey There. I found your blog using msn. This is an extremely well written article. I’ll be sure to bookmark it and return to read more of your useful info. Thanks for the post. I’ll definitely comeback. webflow development agency

    ReplyDelete
  6. And Im running from a standard users account with strict limitations, which I think may be the limiting factor, but Im running the cmd as the system I am currently working on. ui/ux design

    ReplyDelete
  7. This content is written very well. Your use of formatting when making your points makes your observations very clear and easy to understand. Thank you. best brand agencies

    ReplyDelete
  8. Cheers for this excellent. I was wondering whether you were planning of publishing similar posts to this. .Keep up the excellent articles! top front end developers

    ReplyDelete
  9. Enjoyed reading this, very good stuff, thankyou . website designer nyc

    ReplyDelete
  10. I had been honored to receive a call coming from a friend as he observed the important points shared in your site. Looking at your blog publication is a real great experience. Thank you for thinking of readers like me, and I desire for you the best of achievements for a professional surface area. resorts in cuba new york web design company

    ReplyDelete
  11. There is noticeably a lot to realize about this. I suppose you made certain nice points in features also. san francisco brand agency

    ReplyDelete
  12. Outstanding post, I think blog owners should larn a lot from this blog its really user genial . branding sf

    ReplyDelete


  13. Thank you for sharing such a great information.Its really nice and informative.hope more posts from you. I also want to share some information recently i have gone through and i had find the one of the best
    DevOps Training in Chennai | DevOps Training in anna nagar | DevOps Training in omr | DevOps Training in porur | DevOps Training in tambaram | DevOps Training in velachery

    ReplyDelete
  14. Successful visual communication is seen as reasonable, fitting, and valuable.Professional graphic design

    ReplyDelete
  15. I pay a visit every day a few blogs and sites to read articles, but this weblog offers feature based writing.

    leather sofa set

    ReplyDelete
  16. I read this article fully on the topic of the resemblance of most recent and preceding technologies, it’s remarkable article.

    Study in Ireland Consultants

    ReplyDelete
  17. These are truly fantastic ideas regarding blogging. You have touched on some pleasant points here. Any way keep up writing.

    Bada Business

    ReplyDelete
  18. Admiring the dedication you put into your blog and in depth information you provide. It’s awesome to come across a blog every once in a while that isn’t the same old rehashed information. Fantastic read! Software Security Solutions


    ReplyDelete
  19. Today the web development companies have matured into esteemed and dedicated quality service providers, offering website solutions that enhance the prospects of the small and medium sized businesses to prosper online Website Developers

    ReplyDelete
  20. Internet users tend to prefer easy to use websites, because they do not want to have to learn how to use a website every time they find a new one. They should be able to use a website after only a few seconds of looking around a homepage, any more and they will leave and browse elsewhere. web design dubai

    ReplyDelete