You have been redirected from an outdated version of the article. Below is the content available on this topic. To view the old article click here.

Custom Types

A Custom Type is an element of the dynamic data model of a Structr application.

Custom types can be created and configured using the Schema Editor. A custom type has a set of default properties (depending on its Base Type), and can have zero or more dynamic properties of various types. The data model supports simple inheritance, so custom types can extend other custom types to share common properties and methods.

A Simple Data Model

Fig. 1: A base type (User) and two custom types

Remote Attributes

Custom types can be linked to other types, including base types, which can be seen in the above screenshot. Structr will automatically create Remote Attributes on either side of the link, which can then be used to create, update or remove the relationships between instances of the two types.

Views

The properties of a custom type can be combined into named Views, which are accessible under an individual REST URL. Access to these URLs can be configured independently for each HTTP method using Resource Access Grants, which makes them an ideal tool to create specialized endpoints for different client applications (e.g. mobile clients etc.).

Business Logic

Custom types can be extended with scripted business logic, either through the standard Callback Methods, or through Custom Schema Methods. Custom schema methods can be executed from Web Frontend using Action Buttons.

Virtual Types

Custom types and their properties can be mapped and transformed to better support integration with external systems. See Virtual Types for more information about that.

Database Structure

The underlying database structure consists of five types: SchemaNode, SchemaRelationshipNode, SchemaProperty, SchemaView and SchemaMethod. Each custom type is represented by a SchemaNode instance. It can have relationships to other schema nodes via the SchemaRelationshipNode type.

The attributes of a custom type are represented by instances of SchemaProperty, which are linked to the schema node. Views are represented by SchemaView instances, and methods are likewise represented by SchemaMethod instances. Since Structr creates REST resources for all of its known types, schema nodes and all other schema-related types can be managed via REST.

Global Schema Methods

SchemaMethod instances that are not connected to a SchemaNode can be used to provide reusable functions. See the call() function for more information about that.

Search results for "Custom Types"

Canvas

Type names of custom types can be changed by clicking on the text of the type node. When hovering over the type node the context icons are made visible. The Edit button (Pencil icon) opens the details dialog for the type and the Delete button (Delete icon) allows deleting the type after a confirmation.

Visibility

The visibility tools allow hiding/showing of types. The types are grouped into the 5 categories Custom Types, Core Types, UI Types, HTML Types and Uncategorized Types which each contain a table with all types in that category. Each type in those tables can either be shown or hidden. Using the Toggle Visibility Checkbox (Toggle Visibility Checkbox) in the header of each table you can select or deselect all checkboxes in the whole table which sets the types to visible or hidden, similarly clicking the Toggle Type Visibility Icon (Toggle Type Visibility) inverts the current selection of checkboxes.

Features

Structr’s module system provides a large number of built-in functionality you can use in your own custom application. One way to use the provided functions is to create custom types and let them inherit from built-in data types.

Type Details Dialog

There are 5 tabs where the functionality of the type can be configured:

  • Local Attributes
    A Custom Type can be extended with dynamic properties to provide the data model for the intended use-case. This list contains all local properties (meaning they are defined on this type directly).

  • Views
    The properties of a type can be combined into named Views, which are accessible under an individual REST URL. Access to these URLs can be configured independently for each HTTP method using Resource Access Grants, which makes them an ideal tool to create specialised endpoints for different client applications (e.g. mobile clients etc.).

  • Methods
    There are different kinds of methods - callback methods and entity methods. Callback methods are automatically executed by the framework upon certain lifecycle events and have a strict naming convention. Entity methods are called by the user/programmer.
    Entity methods are not automatically run by the framework and must be called manually. This either means making a POST request to /structr/rest/<Type>/<UUID>/<methodName> or in serverside JavaScript as <node>.<methodName>();

  • Remote Attributes
    Custom types can be linked to other types, including base types. Structr will automatically create Remote Attributes on either side of the link, which can then be used to create, update or remove the relationships between instances of the two types. In this tab the configuration of the remote attributes can be viewed and edited. The names configured here are used throughout the application to refer to the other side of the relationship(s).

  • Inherited Attributes
    The content of this tab is of informative character. All inherited attributes are shown with an information from where it was inherited.