Skip to main content

How the Tuskfish content model actually works (v2)

In Tuskfish the different types of content items are represented by a single class that is loosely based on the Dublin Core Metadata Element Set (DCMES), a standard vocabulary of fifteen properties for use in resource description. Most types of web content can be described using a subset of the DCMES properties plus a few other web staples such as a teaser field, view counter, file size and web-specific metadata fields.

The practical upshot of using standardised DCMES properties is that you only need a single data entry form. It doesn't matter whether you are submitting a news article, downloadable file, photo, video, audio file, GPS track, tag or collection; they all have (or can have) a title, creator, image, description, type and so on. The 'type' property is used to distinguish between different kinds of content and assign an appropriate template to display it.

This is essentially what makes Tuskfish so simple, lightweight and robust. Using standard properties for all content items means that all your content can coexist in one database table. Ahhh the light goes on! Suddenly, searching across multiple types of content is fast and straightforward. The code to access and manipulate content objects works for everything. Redundancy is massively reduced allowing the code base to remain small and efficient, which in turn makes it easy to understand and maintain.

Creating new types of content

If you want to add a new type of content you can, so long as it fits the existing content properties. You need to:

  • Add your new content type to trust_path/libraries/tuskfish/class/Tfish/Content/Traits/ContentTypes.php in both the listTypes() and listTemplates().
  • Add your new content type to appropriate whitelists in vendor/tuskfish/contentForm.js, which is used to validate mimetypes in form submissions, and to show/hide fields for different types where necessary.
  • Create a template to display it matching the name you specified in listTemplates(), which should be included in your front-end theme folder(s). Use an existing template as a starting point.

If you want to add some radically different content type for which the DCMES-based parental content object is not suitable, you can although it is more work. You'll need to add a new database table to handle additional properties in line with your needs and design your own controller / model / viewModel classes, but the Tuskfish database and criteria classes will still work. For more details, please refer to the Tuskfish Developer Guide.

Copyright, all rights reserved.