資料 リソース
Liferayは、コミュニティにてテクノロジーをより良く使うために役立つ豊富なリソースと知識を提供しています。
Creating a Hook
Regardless of whether you use the Plugins SDK or your terminal to create hooks, hooks projects are stored in the Plugins SDK’s hooks directory.
Using Developer Studio:
Go to File → New → Liferay Project.
Follow these steps to setup your new hook:
1.1. Enter example for your Project name and Example for your Display name.
2.2. Select the Plugins SDK and Portal Runtime you’ve configured.
2.3. Select the Hook Plugin Type.
2.4. Click Finish.
Figure 6.1: Creating your hook plugin
The Plugins SDK automatically named the hook by appending “-hook” to the project name. With Developer Studio, you can create a completely new plugin or add a new plugin to an existing plugin project.
Using the terminal: Navigate to your Plugins SDK directory in a terminal and enter the appropriate command for your operating system:
In Linux and Mac OS X, enter
./create.sh example “Example”
In Windows, enter
create.bat example “Example”
A BUILD SUCCESSFUL message from Ant tells you there’s a new folder named example-hook inside the Plugins SDK’s hooks folder. The Plugins SDK automatically named the hook by appending “-hook” to the project name.
Deploying the Hook
Using Developer Studio: Click and drag your hook project onto your server. Upon deployment, your server displays messages indicating that your hook was read, registered and is now available for use.
Reading plugin package for example-hook
Registering hook for example-hook
Hook for example-hook is available for use
If you ever need to redeploy your plugin while in Developer Studio, right-click your plugin’s icon located underneath your server and select Redeploy.
Using the terminal: Open a terminal window in your hooks/example-hook directory and enter
ant deploy
A BUILD SUCCESSFUL message indicates your hook is now being deployed. If you switch to the terminal window running Liferay, in a few seconds you should see the message “Hook for example-hook is available for use”.
Note: When we created portlets and themes, they were fully functional upon deployment. Hooks aren’t like that, because they’re Liferay customizations, and the default customization is the original implementation!
Anatomy of the Hook
To make your hook useful, you need to customize something in Liferay. You begin by mirroring the structure of Liferay’s code that you plan to customize. A hook plugin is built to contain this:
example-hook/docroot/
- `META-INF/` - `WEB-INF/` - `lib` - `liferay-hook.xml` - `liferay-plugin-package.properties`build.xml
In Developer Studio’s Package Explorer, here’s what the hook structure looks like:
Figure 6.2: Package Explorer view of hook plugin
The particular files you’ll work on depend on what Liferay feature you’re overriding with your hook. Let’s start making hooks for the features developers override the most; web resources are a good place to start.