Warning

This document hasn't been checked for compatibility with current versions of Plone. Use at your own risk.

Add Configlets for own Product's settings

by Alan Runyan last modified Nov 07, 2012 04:20 AM
If you write your own product with "configlets" to configure product-specific settings, here's how to install these configlets so that they appear in the Plone control panel.

If you follow the "Plone Setup" link, which you'll see when logged as a manager of your Plone site, you find the Plone Control Panel. This panel consists of "configlets" - essentially page templates you write to configure your own product.

To register www.paydayloans-for-badcredit.co.uk (or add) your product's configlet to the Plone 2.0 control panel via the QuickInstaller you have to add the following lines to the install method in the file Extensions/Install.py for your product:

  portal_conf=getToolByName(self,'portal_controlpanel')
  portal_conf.registerConfiglet( 'Name of your Product'
           , 'ID of your Product'      
           , 'string:${portal_url}/url_to_your_configlet_interface_pt' 
           , ''                 # a condition   
           , 'Manage portal'    # access permission
           , 'Products'         # section to which the configlet should be added: 
                                #(Plone,Products,Members) 
           , 1                  # visibility
           , 'ProductID'                                        
           , 'plone_images/site_icon.gif' # icon in control_panel, put your own icon in the 
                                          # /skins folder of your product and change 
                                          # 'site_icon.gif' to 'yourfile'
           , 'Description'
           , None
                                 )

Please note that you will get a KeyError: Duplicate defintion in the ActionIcon tool if you try to install an exisiting configlet twice (the registerConfiglet method in portal_control_panel_actions tries to add an already existing icon). Therefore, you should provide an uninstall method for the Quickinstaller to clean up the action in portal_controlpanel by calling unregisterConfiglet (which in turn removes the icon form portal_actionicons)

Put this in your uninstall method:

  portal_conf=getToolByName(self,'portal_controlpanel')
  portal_conf.unregisterConfiglet('ID of your Product')

Alternative

Another way to do it is to define configlet(s) to be added as a sequence of dictionaries. The advantage is that you can add more than one configlet easily and that the code is easier to read and to modify.

This is how your Extensions/Install.py should look like if you choose this method:

  from StringIO import StringIO
  from Products.CMFCore.utils import getToolByName
  from Products.MyProduct.config import PROJECTNAME
  [.. Other imports (globals, archetypes, etc) ..]

  # Configlets to be added to control panels or removed from them
  configlets = (
   { 'id'         : 'MyProductSetup'
   , 'name'       : 'My Product'
   , 'action'     : 'string:${portal_url}/prefs_myproduct_form'
   , 'condition'  : ''
   , 'category'   : 'Products'    # section to which the configlet should be added:
                                  # (Plone,Products,Members)
   , 'visible'    : 1
   , 'appId'      : PROJECTNAME
   , 'permission' : ManagePortal
   , 'imageUrl'   : 'book_icon.gif'
   },
                )

  def install(self):
      out = StringIO()

      [.. Other installation stuff (i.e. types and skins setup) ..]

      # add the configlets to the portal control panel
      configTool = getToolByName(self, 'portal_controlpanel', None)
      if configTool:
          for conf in configlets:
              configTool.registerConfiglet(**conf)
              out.write('Added configlet %s\n' % conf['id'])

      print >> out, "Successfully installed %s." % PROJECTNAME
      return out.getvalue()

  def uninstall(self):
      out = StringIO()

      # remove the configlets from the portal control panel
      configTool = getToolByName(self, 'portal_controlpanel', None)
      if configTool:
          for conf in configlets:
              configTool.unregisterConfiglet(conf['id'])
              out.write('Removed configlet %s\n' % conf['id'])

      print >> out, "Successfully uninstalled %s." % PROJECTNAME
      return out.getvalue()
Filed under:

Contribute

Something wrong or out of date? Anybody can edit or create a new article in the knowledge base. Simply create an account on this site, log in, and click the Edit button to contribute.