|
| 1 | +--- |
| 2 | +myst: |
| 3 | + html_meta: |
| 4 | + "description": "Creating content types to manage tasks in Plone." |
| 5 | + "property=og:description": "Creating content types to manage tasks in Plone." |
| 6 | + "property=og:title": "Creating content types to manage tasks in Plone." |
| 7 | + "keywords": "Content Types, FTI, Dexterity, plonecli, bobtemplates.plone" |
| 8 | +--- |
| 9 | + |
| 10 | +# Creating content types |
| 11 | + |
| 12 | +When we attempt to solve a particular content management problem with Plone, we will often design new content types. |
| 13 | +For the purpose of this example, we'll build a simple set of types to manage tasks. |
| 14 | + |
| 15 | +- We will use a content type `Tasks` to hold all task objects and present a list of tasks to the user. |
| 16 | + This type is folderish (`Container`). |
| 17 | +- We will use a content type `Task` with the information about the task. |
| 18 | + Fields include name, description, and status of the task. |
| 19 | + This type is non-folderish (`Item`). |
| 20 | + |
| 21 | +## Creating a Plone package |
| 22 | + |
| 23 | +We typically create a content type inside a Plone package. |
| 24 | +We will use the {term}`plonecli` to create a Plone package and our content types. |
| 25 | + |
| 26 | +```shell |
| 27 | +plonecli create addon collective.tasks |
| 28 | +cd collective.tasks |
| 29 | +``` |
| 30 | + |
| 31 | +## Adding content types |
| 32 | + |
| 33 | +Let's add a content type called `Tasks`: |
| 34 | + |
| 35 | +```shell |
| 36 | +plonecli add content_type |
| 37 | +``` |
| 38 | + |
| 39 | +Fill in the name `Tasks` for the first content type: |
| 40 | + |
| 41 | +```console |
| 42 | +-> Content type name (Allowed: _ a-z A-Z and whitespace) [Todo Task]: Tasks |
| 43 | +``` |
| 44 | + |
| 45 | +We keep the default base class `Container` here: |
| 46 | + |
| 47 | +```console |
| 48 | +--> Dexterity base class (Container/Item) [Container]: |
| 49 | +``` |
| 50 | + |
| 51 | +We keep the default `globally addable`: |
| 52 | + |
| 53 | +```console |
| 54 | +--> Should the content type globally addable? [y]: |
| 55 | +``` |
| 56 | + |
| 57 | +We want to filter content types, which can be added to this container: |
| 58 | + |
| 59 | +```console |
| 60 | +--> Should we filter content types to be added to this container? [n]: y |
| 61 | +``` |
| 62 | + |
| 63 | +We keep the default behaviors active: |
| 64 | + |
| 65 | +```console |
| 66 | +--> Activate default behaviors? [y]: |
| 67 | +``` |
| 68 | + |
| 69 | +Now let's add a content type called `Task`: |
| 70 | + |
| 71 | +```shell |
| 72 | +plonecli add content_type |
| 73 | +``` |
| 74 | + |
| 75 | +Fill in the name `Task` for the first content type: |
| 76 | + |
| 77 | +```console |
| 78 | +-> Content type name (Allowed: _ a-z A-Z and whitespace) [Todo Task]: Task |
| 79 | +``` |
| 80 | + |
| 81 | +We change the base class to `Item` here: |
| 82 | + |
| 83 | +```console |
| 84 | +--> Dexterity base class (Container/Item) [Container]: Item |
| 85 | +``` |
| 86 | + |
| 87 | +We don't want it to be globally addable `globally addable`: |
| 88 | + |
| 89 | +```console |
| 90 | +--> Should the content type globally addable? [y]: n |
| 91 | +``` |
| 92 | + |
| 93 | +If we disable `globally addable`, the next question will ask for the parent content type, where we will answer `Tasks`: |
| 94 | + |
| 95 | +```console |
| 96 | +--> Parent container portal_type name: Tasks |
| 97 | +``` |
| 98 | + |
| 99 | +For the rest of the questions, we can keep the defaults. |
| 100 | + |
| 101 | +To test our new Plone package and its content types, we can use {term}`plonecli` to build a development environment and start Plone. |
| 102 | + |
| 103 | +```shell |
| 104 | +plonecli build |
| 105 | +plonecli serve |
| 106 | +``` |
| 107 | + |
| 108 | +Your Plone is now running on http://localhost:8080. |
| 109 | +You can add a new Plone site, enable your add-on, and add your content types. |
| 110 | + |
| 111 | +```{seealso} |
| 112 | +{term}`plonecli` takes care of all the details of a content type and its configuration. |
| 113 | +For more configuration details, see {doc}`fti`. |
| 114 | +``` |
| 115 | + |
| 116 | +For now your content type doesn't have any custom schema with fields defined. |
| 117 | + |
| 118 | +See {doc}`/backend/schemas`, {doc}`/backend/fields` and {doc}`/backend/widgets` for information on how to add custom fields and widgets to your content type. |
| 119 | + |
| 120 | +Also have a look at Plone {doc}`/backend/behaviors`, which provide default features you can enable per content type. |
0 commit comments