Fantastic Extension Points - And Where to Find Them

One more year, it's been great to meet many of you at our events. This time I dedicated one of my workshops to the migration of 6.2 plugin projects to Liferay 7.0. I knew that some of you had already started planning this migration and you would find it helpful, so thanks for the good feedback. And thank you even more for all your questions, as they help us know what your concerns are and what you need to move towards Liferay's latest version.
 
Fortunatelly, it was easy to answer most of your questions. Our Documentation Team has made such a tremendous effort to cover the code migration topics, that I only had to point out the related section in our Developer Network. So kudos to the Docs Teamyes
 
In some cases, however, there's not just a single section I can refer you to. That's the case of the new extension mechanisms in Liferay, for instance, where you'll find dozens of guides each covering a particular use case. Motivated by this fact and by the many questions received during the workshops about the future of extensibility in Liferay, I decided to write this blog entry and guide you through some useful resources on this topic.
 

Hook Plugins in Liferay 6.2

Let's start with a quick review of what you already know: what hooks could do for you to customize Liferay Portal 6.2. If you want to refresh your knowledge, I recommend a quick reading of the Customizing Liferay Portal with Hooks section. To summarize, in Liferay 6.2 we used hooks for:
  • Overriding web resources
  • Customizing JSPs by extending the original
  • Overriding language properties
  • Overriding portal services
  • Creating model listeners
  • Overriding and adding struts actions
  • Performing custom actions
  • Extending indexers
  • Extending other plugins
Liferay 7.0 still supports legacy hook plugins. So first take your time to analyze the pros and cons of continuing with the plugin approach. Here you have a couple of readings on this subject:
In this guide I'll cover the alternatives to hook plugins that Liferay 7.0 offers. As you'll discover, not only are the same customization cases covered in a simpler and more flexible way, but also new extension points, tools and samples are provided.
 

Extenssion Points in Liferay 7.0.

If you're new to OSGi and the modular development in Liferay, let me suggest these articles before you continue reading:
As you see, Liferay 7.0 is about modularity and keeping things small and simple. And the new extension mechanisms follow exactly this pattern. Let's review some of them:
 

Customizing the Portal UI

A typical task that you face in Liferay projects is customizing Liferay Portal's default UI to match your requirements. In Liferay 6.2 this involved using hooks to change the appearance and behavior of the Dockbar and its sections. Liferay 7.0's UI provides new and much powerful ways to customize the main sections in the Product Navigation:
 
 
Furthermore, with Liferay 7.0 it is easier to customize some UI areas where previously hooks or themes were required:
And don't forget about Application Display Templates, one of the easiest, fastest and most powerful ways to customize Liferay applications. With Liferay 7.0 you can customize the portal navigation without writing your own theme. And you can even extend the template context with your custom variables and functionality:

Overriding JSPs

Liferay applications, both in the core and in modules, often contain JSPs. In Liferay 7.0 you can leverage OSGi Fragments hosts to override these files:

Customizing Portlet Behavior

Moving a step down, Liferay also provides extension mechanisms in the control layer. For instance, you can override MVC commands with your own custom logic. If you're migrating from 6.2, take a look to this article about StrutsActionWrappers first. You can even replace the portlet that, by default, is "in charge" of certain actions - like displaying a web content - with yours:

Extending the Model Layer

Liferay's model layer is built with Service Builder. You can learn more about the Service Builder and the generated code in this article. The model layer can be customized and extended for many different purposes. For instance you may want to change how blog entries are created, add some extra fields to the indexed documents or execute your own logic after a web content is updated:

Performing Custom Actions

You can perform custom actions on common portal events (e.g. before or after login) or during module's activation:

Modifying Language Keys

Another common use case in Liferay projects is modifiying or extending the default language keys in core and module applications:

Overriding Portal Properties

Last but not least, in case you need to override Liferay's default properties you can also leverage OSGi fragments (as the ones described for JSPs) for this purpose:

Tools and Samples

What you read in the previous section was just a summary of some Liferay's extension mechanisms. If you really want to learn about them, the best way is to get hands on some code. To make this task easier, Liferay provides code templates for the most common use cases. And this is not all. Developers love examples and replicable code, and we love developers so we have a whole repository full of sample modules for you:
Finally, if you've read the articles I recommended at the beginning of this entry, you should know that all Liferay applications (including Web Content, Wiki, etc.) are now built in the same way as you'll build yours. This means you can also use the Liferay Portal repository as a source of samples for your own projects!
 

Some Final Notes

If you read this far (I know, I know, it's been a long entry) then you have the docs, the tools and the samples to start writing extensions for Liferay 7.0. Please give it a try! Don't forget we're here to help you, so use the  Forums to share any questions or issues you may find.
 
We'll also appreciate any feedback about these materials and how to improve them. And don't forget that you can  contribute to the documentation, the tools and the samples yourself!
Blogs
Hola Eduardo,

this is an excellent reference. Thanks for sharing.

May I also suggest adding a new extension entry for extending the document action menu in the document library ?

Koen Olaerts posted a sample solution in his blog at

* Liferay DXP: Adding Custom Document Actions
** https://blogs.aca-it.be/liferay-dxp-document-actions/

Can you link to Koen's article and also submit a doc change request to include a generic solution in the Liferay Blade Samples Repository ?

Gracias.

Tim
Hey Tim,

Thanks for the feedback. I added a reference and a link to Koen's blog. We provide a basic generic sample in the repository: https://github.com/liferay/liferay-blade-samples/tree/master/liferay-gradle/blade.portlet.configuration.icon. But we may consider extending it or providing more samples for this kind of extension.

Thanks once again