Skip to content. | Skip to navigation

Personal tools
Sections
You are here: Home wiki RepurposeLinkObject

RepurposeLinkObject

Material here copied from Plone.org and reorganised slightly.

The following instructions show you how to create custom or specialized versions of existing objects in Plone. We use the link object as a basis for creating a symlink (similar to a symbolic link in Unix, shortcut in Windows). Another example uses link object to create a redirect object (redirects the browser to some other specified page either inside or outside of Plone).

Symlink.

Repurpose a link object to create a symlink object. A symlink (aka symbolic link) acts as a link to another object in another part of a site. This works in a similar way to ln in Unix, or create shortcut in windows. The existing Link object in Plone is a good candidate for repurposing to a symbolic link or a redirect link because it needs similiar inputs to operate, and the results produced are similar enough too.

  1. First we repurpose the Link object, in the ZMI go to portal_types
    • in the Select type to add... box select Factory-based Type Info
      • id: Symlink
      • use default type information: CMFDefault: Link

    You have now successfully created a new symlink class based on the Link class and the default Factory Type Information for Link.

  2. Now we change the default view actions to call different methods (these methods don't exist just yet)
    • click on newly created Symlink type
      • change Initial view name to link_edit_form (then Save Changes)
      • click actions tab
      • change View action to action: string:${object_url}/symlink_view (then Save)

      You have now changed the symlink class so that its default view action will run a method called symlink_view. You will note that the original action went tolink_view which is a template inportal_skins/plone_content/link_view. We need to create a new script called symlink_view which provides our symlink functionality.

  3. Create the new symlink_view python script that will perform like a symlink using the information entered by a user as the url attribute for the newly createdSymlink content type.
    • click on portal_skins and then into the custom folder
    • in the Select type to add... box, select (Script) Python
      • id: symlink_view

    Zope adds a default python script called symlink_view, click on it to edit it. You won't need to enter values for title or parameter list (these should be blank) just change the body: to be as follows:

            return context.restrictedTraverse(context.remote_url)()
    

     

    • click save

    Now we have it so that when you view a Symlink it will display the values entered in the url attribute of the Sylink edit form (it reuses the Link edit form). But first we need to fix an oversight so when you click on a object in folder_contents it will bring you to the edit_form instead of the view_form - or you wont be able to easily edit the content!

  4. Change behaviour when clicking on an object in folder_contents fromview_form to edit_form
    • click on portal_skins and then into plone_templates folder
    • click on folder_contents
    • select custom in the dropdown box and click customize button, you are now at the edit screen of the folder_contents pagetemplate
    • look for the line that says:
            **In Plone 1** td tal:define="action python:item.getTypeInfo().getActionById(view);
            **In Plone 2** td tal:define="action python:item_typeinfo.getActionById(view);
      

    replace it with:

          **In Plone 1** td tal:define="action python:item.getTypeInfo().immediate_view;
          **In Plone 2** td tal:define="action python:item_typeinfo.immediate_view;
    

     

    (this will be in newer plones)

Redirect.

Repurpose a link object to create a redirect object. A redirect acts to force the browser to open the URL given, either locally or on another site.

  1. First we repurpose the Link object, in the ZMI go to portal_types
    • in the Select type to add... box select Factory-based Type Info
      • id: Redirect
      • use default type information: CMFDefault: Link

    You have now successfully created a new redirect class based on the Link class and the default Factory Type Information for Link.

  2. Now we change the default view actions to call different methods (these methods don't exist just yet)
    • click on newly created Redirect type
      • change Initial view name to link_edit_form (then Save Changes)
      • click actions tab
      • change View action to string:${object_url}/redirect_view(then Save)

      You have now changed the redirect class so that its default view action will run a method called redirect_view. You will note that the original action went tolink_view which is a template inportal_skins/plone_content/link_view. We need to create a new script called redirect_view which provides our symlink functionality.

  3. Create the new redirect_view python script that will perform like a redirect using the information entered by a user as the url attribute for the newly createdRedirect content type.
    • click on portal_skins and then into the custom folder
    • in the Select type to add... box, select (Script) Python
      • id: redirect_view

    Zope adds a default python script called redirect_view, click on it to edit it. You won't need to enter values for title or parameter list (these should be blank) just change the body: to be as follows:

            return context.REQUEST.RESPONSE.redirect(context.remote_url)
    

     

    • click save

    Now we have it so that when you view a Redirect it will display the values entered in the url attribute of the Redirect edit form (it reuses the Link edit form). As before for symlink we need to have applied the general fix so when you click on a object infolder_contents it will bring you to the edit_form instead of the view_form - or you wont be able to easily edit the content!