The Documents and Media API also lets you delete file shortcuts. To do so, use
the
DLAppService
method
deleteFileShortcut
with the ID of the shortcut you want to delete:
deleteFileShortcut(long fileShortcutId)
Follow these steps to use this method to delete a file shortcut:
-
Get a reference to
DLAppService
:@Reference private DLAppService _dlAppService;
For more information on this, see the section on getting a service reference in the getting started tutorial.
-
Get the file shortcut’s ID. Since it’s common to delete a file shortcut specified by the end user, you can extract its ID from the request. This example does so via
javax.portlet.ActionRequest
andParamUtil
, but you can do this any way you wish:long fileShortcutId = ParamUtil.getLong(actionRequest, "fileShortcutId");
-
Use the service reference to call the
deleteFileShortcut
method with the file shortcut ID from the previous step:_dlAppService.deleteFileShortcut(fileShortcutId);
You can find the full code for this example in the deleteFileShortcut
method
of Liferay DXP’s
EditFileShortcutMVCActionCommand
class. This class uses the Documents and Media API to implement almost all the
FileShortcut
actions that the Documents and Media app supports. Also note that
this deleteFileShortcut
method, as well as the rest of
EditFileShortcutMVCActionCommand
, contains additional logic to suit the
specific needs of the Documents and Media app.