Extend Default Content Types

Hi!

I have many custom content types with a Python Schema and it's works fine, but some of them are very similar to default content types (event, new item, page...). I want to extend the default types to add or override the fields of each default type with a Python Schema too. How can i do it?

I'm working with Dexterity and Plone 5.0.

Thanks in advance and regards

@spolpen

Check out the following links from Plone 5 training tutorial about Dexterity Types:

https://training.plone.org/5/mastering-plone/dexterity.html

https://training.plone.org/5/mastering-plone/export_code.html

https://training.plone.org/5/mastering-plone/dexterity_2.html

https://training.plone.org/5/mastering-plone/dexterity_3.html

Sure you will found the answer there :wink:

1 Like

Most of the fields of Plone default content types come from behaviors. To modify them you can make your product to override some properties.

Under the profiles/default/types add the Type.xml with the properties you want to override.

A quick example of how to make News Item folderish:

interfaces.py

# -*- coding: utf-8 -*-
from plone.app.contenttypes.interfaces import INewsItem as INewsItemOriginal

class INewsItem(INewsItemOriginal):
    """ Folderish News """

Note I subclass News Item Interface to have available the views registered to the original interface

contents.py

# -*- coding: utf-8 -*-
from plone.dexterity.content import Container
from zope.interface import implementer
from .interfaces import INewsItem

@implementer(INewsItem)
class NewsItem(Container):
    """Convenience subclass for ``News Item`` portal type
    """

profiles/default/type/News_Item.xml

<?xml version="1.0"?>
<object
    i18n:domain="plone"
    meta_type="Dexterity FTI"
    name="News Item"
    xmlns:i18n="http://xml.zope.org/namespaces/i18n">
    <!-- Hierarchy control -->
    <property name="filter_content_types">False</property>
    <property name="klass">my.product.contents.NewsItem</property>
    <property name="schema">my.product.interfaces.INewsItem</property>
</object>
2 Likes