This module is the base class of
apostrophe-global and any other module that serves as the manager for a
doc type. You can introduce new fields to the schema of all docs by
extending this module at project level and modifying
name option must be set to the doc type name, as found in the
property of each individual doc. Thus it is usually singular.
By default, fields for setting detailed permissions for users and groups to view and edit a particular doc are not displayed. If you turn on this flag, they are added to the schema.
(Note that when a user who is not an admin for your doc type creates a new one, they are automatically given permission to edit it as an individual so they can continue to manage it.)
The standard schema options, including
See the schema guide.
Returns the minimum permission name that should be checked for to determine if this user has some edit privileges for this doc type (not necessarily every instance of it), for example the ability to create one. Determines admin bar menu item visibility
Returns the minimum permission name that should be checked for to determine if this user has full admin privileges for this doc type
Define the related type "cursor", so that all of our subclasses automatically have a cursor type too, and it is autoloaded from ./lib/cursor.js if that exists, otherwise given an empty definition.
Returns a cursor that will only yield docs of the appropriate type
as determined by the
name option of the module. Returns a cursor of
the appropriate type for the current module, even if it is a subclass.
Returns a cursor for use in finding docs. See cursor.js for chainable
filters, and also yielders that actually deliver the docs to you.
Returns a new instance of the doc type, with the appropriate default values for each schema field.
Returns a MongoDB projection object to be used when querying
for this type if all that is needed is a title for display
in an autocomplete menu. Default behavior is to
return only the
Removing any of these three is not recommended.
query.field will contain the schema field definition for
the join the user is attempting to match titles from.
Returns a string to represent the given
doc in an
doc will contain only the fields returned
query.field will contain
the schema field definition for the join the user is attempting
to match titles from. The default behavior is to return
title property. This is sometimes extended to include
event start dates and similar information that helps the
user distinguish between docs.
apostrophe-versions to label changes that
are made to joins by ID. Set
change.text to the
Returns true if only admins are allowed to edit this type. Respected by the pieces module when deciding whether to enumerate more specific permissions as choices for this module.
Return a new schema containing only fields for which the
current user has the permission specified by the
property of the schema field, or there is no
permission property for the field.
In the schema,
initially locked down to sitewide admins. Now that
we've constructed the module completely, take advantage
getAdminPermissionName to specify a more nuanced permission,
such as the admin permission for this piece type, or for pages
This method provides the back end of /autocomplete routes. For the implementation of the autocomplete() filter see autocomplete.js.
"query" must contain a "field" property which is the schema join field that describes the relationship we're adding items to.
"query" must also contain a "term" property, which is a partial string to be autocompleted; otherwise an empty array is delivered to the callback.
We don't launder the input here, see the 'autocomplete' route.
Adds a listener for the
docSearchIndex Apostrophe event, pointing to the
Invoked when a
docSearchIndex event takes place, this method adds
additional search texts to the
texts array (modify it in place by
pushing new objects to it). These texts influence search results.
The default behavior is quite useful, so you won't often need to
Each "text" is an object and must have at least
weight is >= 10, the text will be included in autocomplete searches and
given higher priority in full-text searches. Otherwise it will be included
only in full-text searches.
searchSummary property will not contain
By default this method invokes
schemas.indexFields, which will push
texts for all of the schema fields that support this unless they are
In any case, the text of rich text widgets is always included as lower-priority search text.
Before sending any page, create the singleton for working with this type of piece, but only if there is an active user