Contents
Use invokeFactory(portal_type, id). invokeFactory() is available on all folderish content objects.
Example (from unit tests):
self.loginAsPortalOwner()
self.portal.invokeFactory("Folder", "folder")
self.portal.folder.invokeFactory("Folder", "subfolder")
self.portal.folder.subfolder.invokeFactory("Document", "doc")
Plone can restrict available content types which you can create in folder through Add... menu.
portal_types defines which content can be created inside which content type. This is allowed_content_types setting and you can change it through ZMI as well.
You can set the restriction in GenericSetup profiles/default/types/YourType.xml:
<property name="filter_content_types">True</property>
<property name="allowed_content_types">
<element value="YourContentTypeName" />
<element value="Image" />
<element value="News Item" />
...
</property>
In UI, you can access this feature through Add... menu Restrict option.
Type contraining is managed by ATContentTypes product
Example:
# Set allowed content types
from Products.ATContentTypes.lib import constraintypes
# Enable contstraining
folder.setConstrainTypesMode(constraintypes.ENABLED)
# Types for which we perform Unauthorized check
folder.setLocallyAllowedTypes(["ExperienceEducator"])
# Add new... menu listing
folder.setImmediatelyAddableTypes(["ExperienceEducator"])
You can also override contraintypes accessor method to have programmable logic which types are addable and which not.
More info
Zope has facilities for basic folder and contained objects by OFS subsystem. You do not need to work with raw objects unless you are doing your custom lightweight, Plone free, persistent data.
More examples in
The following applies to Archetypes based objects only.
Archetypes content contruction has two phases
You are supposed to call either object.unmarkCreationFlag() or object.processForm() after content is created manually using invokeFactory().
processForm() will perform following tasks:
If you don’t want to do particular step, look to Archetypes/BaseObject.py and call only what you really want. But unless unmarkCreationFlag() is called the object will behave strangely after the first edit.
Factory type information (FTI) is responsible for content creation in the portal. It is independend from content type (Archetypes, Dexteriry) subsystems.
Warning
FTI codebase is historical (updated circa 2001). Useful documentation might be hard to find.
FTI is responsible for
See
Archetypes have a hook called initializeArchetype(). Your content type subclass can override this.
Example:
class LandingPage(folder.ATFolder):
"""Landing page"""
def initializeArchetype(self, **kwargs):
"""
Prepopulate folder during the creation.
Create five subfolders of "BigBlock" type, with title and id preset.
"""
folder.ATFolder.initializeArchetype(self, **kwargs)
for i in range(0, 5):
id = "container" + str(i)
self.invokeFactory("BigBlock", id, title="Big block " + str(i+1))
item = self[id]
# Clear creation flag so that edit screen
item.markCreationFlag()