Entity
MMO.elements · 1 symbol · generated 5 Oct 2026
Entity
Entity.js:5- Namespace
MMO.elements- Extends
- Map
Index
| errors readonly accessor | The server side validation errors, indexed by property name. | |
| uid accessor | The entity's absolute identifier: {collection url}#{id}. | |
| collection accessor | 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. | |
| label accessor | Short human readable name: the label property, its metadata counterpart, or the uid. | |
| title accessor | Long human readable name: the title property, its metadata counterpart, or the label. | |
| view readonly accessor | The view used to edit this entity, declared by its schema as $view. | |
| From(obj, schema, _hash) static | Create an Entity from data. | |
| FromUID(uid, schema) static | Build an entity from its uid and load it from the server straight away. | |
| FromClass(schema, data, collection) static async | Create an entity from a schema | |
| FromID(collection, id, repository) static | Fetch 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) static | Split 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) async | Save 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:110The server side validation errors, indexed by property name.
- Type
- ?MMO.core.Map
uid
accessorEntity.js:204The entity's absolute identifier: {collection url}#{id}.
- Type
?string
collection
accessorEntity.js:225The 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.
- Type
?string
label
accessorEntity.js:246Short human readable name: the label property, its metadata counterpart, or the uid.
- Type
string
title
accessorEntity.js:259Long human readable name: the title property, its metadata counterpart, or the label.
- Type
string
view
readonlyaccessorEntity.js:523The view used to edit this entity, declared by its schema as $view.
- Type
?string
Methods41
From(obj, schema, _hash)
staticEntity.js:14Create an Entity from data.
| obj | string | object | Map | the data to create the entity from |
| schema = null | Promise | object | null | the associated schema |
| _hash = new WeakMap() | WeakMap | [internal] used to prevent infinite recursion |
FromUID(uid, schema)
staticEntity.js:40Build an entity from its uid and load it from the server straight away.
| uid | string | |
| schema = null | ?(MMO.schemas.Schema | Promise) | |
| returns | Promise<MMO.elements.Entity> | resolved once the server has answered |
FromClass(schema, data, collection)
staticasyncEntity.js:52Create an entity from a schema
| schema | string | MMO.schemas.Schema | Promise | if a string, it has to be a valid PHP classname for a registered entity (registered in the repository controller) |
| data = {} | object | the data to create the entity with (properties not present in the schema are ignored) |
| collection = null | ||
| returns | MMO.elements.Entity |
FromID(collection, id, repository)
staticEntity.js:66Fetch an entity from its id
| collection | ||
| id | ||
| repository = null | ||
| returns | Promise<void> |
constructor(args)
Entity.js:73| ...args |
clone(_hash)
Entity.js:82Clone data of an entity, creating a different one with the same data
| _hash = new WeakMap() | ||
| returns | MMO.elements.Entity |
isOpacified()
Entity.js:101isValid()
Entity.js:117| returns | boolean | true when no property carries an error |
isPropertyValid(key)
Entity.js:125| key | string | |
| returns | boolean | true when this property carries no error |
getPropertyError(key)
Entity.js:134Get the error MESSAGE for a property.
| key | string | |
| returns | * | undefined when the property is valid |
getPropertyErrorValue(key)
Entity.js:147Get the value that TRIGGERED a property's error.
| key | string | |
| returns | * | undefined when the property is valid |
setValue(value)
Entity.js:156| value |
connectChild(map, key)
Entity.js:173Override: 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.
| map | MMO.core.Map | the child |
| key | string | number |
ExtractIDAndCollection(uid)
staticEntity.js:192Split a uid into its two meaningful parts.
| uid | string | |
| returns | [string, string] | the id and the collection name |
| throws | Error | when the uid carries no '#' |
isEmpty()
Entity.js:270hasId()
Entity.js:277| returns | boolean | true when the entity exists on the server (0 is a valid id) |
isEmbedded()
Entity.js:286An embedded entity lives inside another one and is saved with it.
| returns | boolean |
setLink(link)
Entity.js:295Fill this entity from an http Link header: the href becomes the uid, every other property goes to metadata.
| link | string | @example '<https://x/api/users#7>title="Bob"' |
toLink()
Entity.js:317Serialise this entity as an http Link header, carrying its uid and title.
| returns | string | |
| throws | string | when the entity has no uid |
toString()
Entity.js:324| returns | string | the title |
toHTML()
Entity.js:332Render the entity as a chip carrying its title and a button opening its edit panel.
| returns | Element |
api(collection, repository)
Entity.js:349Get an API requester from the entity.
| 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. |
| returns | MMO.core.APIRequester |
reload()
Entity.js:359Re-read this entity from the server and overwrite its content with the answer.
| returns | Promise<Object> | the raw API response |
| throws | MMO.Error | when the entity has no uid |
getEditUrl()
Entity.js:374| returns | string | the url of the framework's edit page for this entity |
save(collection, repository)
asyncEntity.js:385Save the entity using the APIRequester.
| 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. |
| returns | self |
remove(collection, repository)
Entity.js:441Delete this entity on the server, then merge back whatever it answers.
| collection = null | ?string | only needed when the entity did not come from the API |
| repository = null | ?string | only needed when the entity did not come from the API |
| returns | Promise<void> | |
| throws | MMO.Error | when the entity has no id |
patch(status, collection, repository)
Entity.js:456Change only this entity's status on the server.
| status | string | one of DRAFT, PENDING, ACTIVE, VALIDATED, FINAL, ARCHIVE |
| collection = null | ?string | only needed when the entity did not come from the API |
| repository = null | ?string | only needed when the entity did not come from the API |
| returns | Promise<Object> | |
| throws | MMO.Error | when the entity has no id |
setActive(collection, repository)
Entity.js:465Shorthand for patch('ACTIVE'). MMO.elements.Entity#patch
| collection = null | ||
| repository = null |
setFinal(collection, repository)
Entity.js:470Shorthand for patch('FINAL'). A final entity cannot be saved any more.
| collection = null | ||
| repository = null |
setValidated(collection, repository)
Entity.js:475Shorthand for patch('VALIDATED'). MMO.elements.Entity#patch
| collection = null | ||
| repository = null |
setPending(collection, repository)
Entity.js:480Shorthand for patch('PENDING'). MMO.elements.Entity#patch
| collection = null | ||
| repository = null |
setDraft(collection, repository)
Entity.js:485Shorthand for patch('DRAFT'). MMO.elements.Entity#patch
| collection = null | ||
| repository = null |
isDraft()
Entity.js:494The status predicates below read the status property, which the server writes in lower case. They are mutually exclusive.
| returns | boolean |
isPending()
Entity.js:498isActive()
Entity.js:502isValidated()
Entity.js:506isFinal()
Entity.js:510isArchive()
Entity.js:514renderView(node, basepath, ref, scope)
Entity.js:535Render the view used to edit this entity
| node | ||
| basepath = '' | ||
| ref = null | ||
| scope = null | ||
| returns | MMO.elements.View |
createNew(data)
Entity.js:546Create a new entity of the same collection
| data = {} |
edit(path, collection, repository, view, target)
Entity.js:557Open the app panel to edit this entity
| path = '' | ||
| collection = null | ||
| repository = null | ||
| view = null | ||
| target = '_blank' | string | where a view that is a page url opens: a new tab by default, _self in this one |
| returns | Promise<MMO.elements.MMO_elements_Entity> | the promise return null if the user canceled the creation |