Documentation
¶
Index ¶
- Variables
- func GetSupportedFeatures() []string
- func Validate(pt PostType) error
- func ValidateName(name string) error
- func ValidateSlug(slug string) error
- func ValidateSupports(supports []string) error
- type PostType
- type Service
- func (s *Service) GetAll() []PostType
- func (s *Service) GetAllBySupports(feature string) []PostType
- func (s *Service) GetBySlug(slug string) (PostType, error)
- func (s *Service) GetFieldsByPostType(slug string) ([]customfield.FieldSchema, error)
- func (s *Service) GetSystemFieldsByPostType(slug string) ([]customfield.FieldSchema, error)
- func (s *Service) GetUserFields() []customfield.FieldSchema
- func (s *Service) GetUserSystemFieldSlugs() []string
- func (s *Service) GetUserSystemFields() []customfield.FieldSchema
- func (s *Service) IsSupported(pt PostType, feature string) bool
- func (s *Service) LoadConfigFromFile(path string) error
- func (s *Service) Register(pt PostType) error
- type UserFields
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidPostTypeName is returned when post type name validation fails ErrInvalidPostTypeName = errors.New("post type name is required and must be between 1 and 200 characters") // ErrInvalidPostTypeSlug is returned when post type slug validation fails ErrInvalidPostTypeSlug = errors.New("post type slug must be between 1 and 200 characters and contain only lowercase letters, numbers, hyphens, and underscores") // ErrInvalidSupports is returned when supports validation fails ErrInvalidSupports = errors.New("supports must contain at least one valid feature") // ErrDuplicatePostType is returned when attempting to register a duplicate post type ErrDuplicatePostType = errors.New("post type with this slug already exists") // ErrPostTypeNotFound is returned when a post type is not found ErrPostTypeNotFound = errors.New("post type not found") )
var SupportedFeatures = []string{
"title",
"content",
"tags",
"featured_image",
"excerpt",
}
SupportedFeatures returns the list of valid feature names
Functions ¶
func GetSupportedFeatures ¶
func GetSupportedFeatures() []string
GetSupportedFeatures returns a copy of the supported features list
func ValidateName ¶
ValidateName validates the post type name field
func ValidateSlug ¶
ValidateSlug validates the post type slug field
func ValidateSupports ¶
ValidateSupports validates the supports array
Types ¶
type PostType ¶
type PostType struct {
Name string `json:"name" toml:"name"`
Slug string `json:"slug" toml:"slug"`
Description string `json:"description,omitempty" toml:"description,omitempty"`
Supports []string `json:"supports" toml:"supports"`
Fields []customfield.FieldSchema `json:"fields,omitempty" toml:"fields,omitempty"`
SystemFields []customfield.FieldSchema `json:"systemFields,omitempty" toml:"system_fields,omitempty"`
}
PostType represents a custom post type configuration
func GetDefaultPostTypes ¶
func GetDefaultPostTypes() []PostType
GetDefaultPostTypes returns the default post types
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service manages post type registration and lookup
func NewService ¶
func NewService() *Service
NewService creates a new post type service initialized with default post types
func (*Service) GetAllBySupports ¶
GetAllBySupports returns all post types that support the given feature
func (*Service) GetFieldsByPostType ¶
func (s *Service) GetFieldsByPostType(slug string) ([]customfield.FieldSchema, error)
GetFieldsByPostType returns the custom field schemas for a given post type slug
func (*Service) GetSystemFieldsByPostType ¶
func (s *Service) GetSystemFieldsByPostType(slug string) ([]customfield.FieldSchema, error)
GetSystemFieldsByPostType returns the system field schemas for a given post type slug
func (*Service) GetUserFields ¶
func (s *Service) GetUserFields() []customfield.FieldSchema
GetUserFields returns the custom user field schemas
func (*Service) GetUserSystemFieldSlugs ¶
GetUserSystemFieldSlugs returns only the slugs of system user fields
func (*Service) GetUserSystemFields ¶
func (s *Service) GetUserSystemFields() []customfield.FieldSchema
GetUserSystemFields returns the system user field schemas
func (*Service) IsSupported ¶
IsSupported checks if a post type supports a specific feature
func (*Service) LoadConfigFromFile ¶
LoadConfigFromFile loads post types from a TOML configuration file If the file doesn't exist, it uses default post types (no error returned)
func (*Service) Register ¶
Register registers a new post type. A non-default slug is validated in full and stored; a slug matching a built-in type (post/page/media/comment) instead EXTENDS that built-in — its Fields and SystemFields are merged in (by slug), preserving the built-in's Name/Description/Supports/identity. Only the fields are validated on the extension path, because an extension entry legitimately omits name/supports (it is not defining a new type).
type UserFields ¶
type UserFields struct {
Fields []customfield.FieldSchema `json:"fields,omitempty" toml:"fields,omitempty"`
SystemFields []customfield.FieldSchema `json:"systemFields,omitempty" toml:"system_fields,omitempty"`
}
UserFields holds global custom and system fields for user profiles
func (UserFields) Validate ¶
func (uf UserFields) Validate() error