Index

Entity

MMO.elements · 1 symbol · generated 5 Oct 2026

class

Entity

Entity.js:5
class MMO.elements.Entity extends MMO.core.Map
Namespace
MMO.elements
Extends
Map

Index

errors readonly accessorThe server side validation errors, indexed by property name.
uid accessorThe entity's absolute identifier: {collection url}#{id}.
collection accessorThe collection this entity belongs to: read from the uid, or from the value that was set explicitly when the entity did not come from the API.
label accessorShort human readable name: the label property, its metadata counterpart, or the uid.
title accessorLong human readable name: the title property, its metadata counterpart, or the label.
view readonly accessorThe view used to edit this entity, declared by its schema as $view.
From(obj, schema, _hash) staticCreate an Entity from data.
FromUID(uid, schema) staticBuild an entity from its uid and load it from the server straight away.
FromClass(schema, data, collection) static asyncCreate an entity from a schema
FromID(collection, id, repository) staticFetch an entity from its id
constructor(args)
clone(_hash)Clone data of an entity, creating a different one with the same data
isOpacified()
isValid()
isPropertyValid(key)
getPropertyError(key)Get the error MESSAGE for a property.
getPropertyErrorValue(key)Get the value that TRIGGERED a property's error.
setValue(value)
connectChild(map, key)Override: an entity nested inside another one and carrying no id of its own is EMBEDDED.
ExtractIDAndCollection(uid) staticSplit a uid into its two meaningful parts.
isEmpty()
hasId()
isEmbedded()An embedded entity lives inside another one and is saved with it.
setLink(link)Fill this entity from an http Link header: the href becomes the uid, every other property goes to metadata.
toLink()Serialise this entity as an http Link header, carrying its uid and title.
toString()
toHTML()Render the entity as a chip carrying its title and a button opening its edit panel.
api(collection, repository)Get an API requester from the entity.
reload()Re-read this entity from the server and overwrite its content with the answer.
getEditUrl()
save(collection, repository) asyncSave the entity using the APIRequester.
remove(collection, repository)Delete this entity on the server, then merge back whatever it answers.
patch(status, collection, repository)Change only this entity's status on the server.
setActive(collection, repository)Shorthand for patch('ACTIVE').
setFinal(collection, repository)Shorthand for patch('FINAL').
setValidated(collection, repository)Shorthand for patch('VALIDATED').
setPending(collection, repository)Shorthand for patch('PENDING').
setDraft(collection, repository)Shorthand for patch('DRAFT').
isDraft()The status predicates below read the status property, which the server writes in lower case.
isPending()
isActive()
isValidated()
isFinal()
isArchive()
renderView(node, basepath, ref, scope)Render the view used to edit this entity
createNew(data)Create a new entity of the same collection
edit(path, collection, repository, view, target)Open the app panel to edit this entity

Properties6

errors

readonlyaccessorEntity.js:110

The server side validation errors, indexed by property name.

get errors()
Type
?MMO.core.Map
An error is either a message, or `[offending value, message]`.

uid

accessorEntity.js:204

The entity's absolute identifier: {collection url}#{id}.

get uid() set uid(value)
Type
?string

collection

accessorEntity.js:225

The collection this entity belongs to: read from the uid, or from the value that was set explicitly when the entity did not come from the API.

get collection() set collection(value)
Type
?string

label

accessorEntity.js:246

Short human readable name: the label property, its metadata counterpart, or the uid.

get label() set label(value)
Type
string

title

accessorEntity.js:259

Long human readable name: the title property, its metadata counterpart, or the label.

get title() set title(value)
Type
string

view

readonlyaccessorEntity.js:523

The view used to edit this entity, declared by its schema as $view.

get view()
Type
?string
A value starting with '/' is a page url rather than a registered view name.

Methods41

From(obj, schema, _hash)

staticEntity.js:14

Create an Entity from data.

static From(obj, schema = null, _hash = new WeakMap())
objstring | object | Mapthe data to create the entity from
schema = nullPromise | object | nullthe associated schema
_hash = new WeakMap()WeakMap[internal] used to prevent infinite recursion

FromUID(uid, schema)

staticEntity.js:40

Build an entity from its uid and load it from the server straight away.

static FromUID(uid, schema = null)
uidstring
schema = null?(MMO.schemas.Schema | Promise)
returnsPromise<MMO.elements.Entity>resolved once the server has answered

FromClass(schema, data, collection)

staticasyncEntity.js:52

Create an entity from a schema

static async FromClass(schema, data = {}, collection = null)
schemastring | MMO.schemas.Schema | Promiseif a string, it has to be a valid PHP classname for a registered entity (registered in the repository controller)
data = {}objectthe data to create the entity with (properties not present in the schema are ignored)
collection = null
returnsMMO.elements.Entity

FromID(collection, id, repository)

staticEntity.js:66

Fetch an entity from its id

static FromID(collection, id, repository = null)
collection
id
repository = null
returnsPromise<void>

clone(_hash)

Entity.js:82

Clone data of an entity, creating a different one with the same data

clone(_hash = new WeakMap())
_hash = new WeakMap()
returnsMMO.elements.Entity

isValid()

Entity.js:117
isValid()
returnsbooleantrue when no property carries an error

isPropertyValid(key)

Entity.js:125
isPropertyValid(key)
keystring
returnsbooleantrue when this property carries no error

getPropertyError(key)

Entity.js:134

Get the error MESSAGE for a property.

getPropertyError(key)
keystring
returns*undefined when the property is valid

getPropertyErrorValue(key)

Entity.js:147

Get the value that TRIGGERED a property's error.

getPropertyErrorValue(key)It is the rejected input when the server sent one back, and the current value otherwise.
keystring
returns*undefined when the property is valid

connectChild(map, key)

Entity.js:173

Override: an entity nested inside another one and carrying no id of its own is EMBEDDED. It cannot be saved on its own, so it keeps a link back to its owner.

connectChild(map, key)
mapMMO.core.Mapthe child
keystring | number

ExtractIDAndCollection(uid)

staticEntity.js:192

Split a uid into its two meaningful parts.

static ExtractIDAndCollection(uid)
uidstring
returns[string, string]the id and the collection name
throwsErrorwhen the uid carries no '#'
ExtractIDAndCollection('https://x/api/users#7') => ['7', 'users']

hasId()

Entity.js:277
hasId()
returnsbooleantrue when the entity exists on the server (0 is a valid id)

isEmbedded()

Entity.js:286

An embedded entity lives inside another one and is saved with it.

isEmbedded()
returnsboolean

toHTML()

Entity.js:332

Render the entity as a chip carrying its title and a button opening its edit panel.

toHTML()
returnsElement

api(collection, repository)

Entity.js:349

Get an API requester from the entity.

api(collection = null, repository = null)If the entity was obtained through an APIRequester, collection and repository are already set (parameters are ignored).
collection = null?string[optional] only use this parameter if the entity was not obtained from the APIRequester.
repository = null?string[optional] only use this parameter if the entity was not obtained from the APIRequester.
returnsMMO.core.APIRequester

reload()

Entity.js:359

Re-read this entity from the server and overwrite its content with the answer.

reload()
returnsPromise<Object>the raw API response
throwsMMO.Errorwhen the entity has no uid

getEditUrl()

Entity.js:374
getEditUrl()
returnsstringthe url of the framework's edit page for this entity

save(collection, repository)

asyncEntity.js:385

Save the entity using the APIRequester.

async save(collection = null, repository = null)After the save, this entity is reset to the correct values stored on the server.
collection = null?string[optional] only use this parameter if the entity was not obtained from the APIRequester.
repository = null?string[optional] only use this parameter if the entity was not obtained from the APIRequester.
returnsself

remove(collection, repository)

Entity.js:441

Delete this entity on the server, then merge back whatever it answers.

remove(collection = null, repository = null)
collection = null?stringonly needed when the entity did not come from the API
repository = null?stringonly needed when the entity did not come from the API
returnsPromise<void>
throwsMMO.Errorwhen the entity has no id

patch(status, collection, repository)

Entity.js:456

Change only this entity's status on the server.

patch(status, collection = null, repository = null)
statusstringone of DRAFT, PENDING, ACTIVE, VALIDATED, FINAL, ARCHIVE
collection = null?stringonly needed when the entity did not come from the API
repository = null?stringonly needed when the entity did not come from the API
returnsPromise<Object>
throwsMMO.Errorwhen the entity has no id

setActive(collection, repository)

Entity.js:465

Shorthand for patch('ACTIVE'). MMO.elements.Entity#patch

setActive(collection = null, repository = null)
collection = null
repository = null

setFinal(collection, repository)

Entity.js:470

Shorthand for patch('FINAL'). A final entity cannot be saved any more.

setFinal(collection = null, repository = null)
collection = null
repository = null

setValidated(collection, repository)

Entity.js:475

Shorthand for patch('VALIDATED'). MMO.elements.Entity#patch

setValidated(collection = null, repository = null)
collection = null
repository = null

setPending(collection, repository)

Entity.js:480

Shorthand for patch('PENDING'). MMO.elements.Entity#patch

setPending(collection = null, repository = null)
collection = null
repository = null

setDraft(collection, repository)

Entity.js:485

Shorthand for patch('DRAFT'). MMO.elements.Entity#patch

setDraft(collection = null, repository = null)
collection = null
repository = null

isDraft()

Entity.js:494

The status predicates below read the status property, which the server writes in lower case. They are mutually exclusive.

isDraft()
returnsboolean

renderView(node, basepath, ref, scope)

Entity.js:535

Render the view used to edit this entity

renderView(node, basepath = '', ref = null, scope = null)
node
basepath = ''
ref = null
scope = null
returnsMMO.elements.View

createNew(data)

Entity.js:546

Create a new entity of the same collection

createNew(data = {})
data = {}

edit(path, collection, repository, view, target)

Entity.js:557

Open the app panel to edit this entity

edit(path = '', collection = null, repository = null, view = null, target = '_blank')
path = ''
collection = null
repository = null
view = null
target = '_blank'stringwhere a view that is a page url opens: a new tab by default, _self in this one
returnsPromise<MMO.elements.MMO_elements_Entity>the promise return null if the user canceled the creation
entity.edit('', null, null, null, '_self'); //the entity's page replaces the current one