BaseElementAdapter ​
- Type
- Abstract Class
- Namespace
- craft\mcp\elements
- Inherits
- craft\mcp\elements\BaseElementAdapter
- Implements
- craft\mcp\elements\ElementAdapter
- Extended by
- craft\mcp\elements\adapters\AddressAdapter, craft\mcp\elements\adapters\AssetAdapter, craft\mcp\elements\adapters\EntryAdapter, craft\mcp\elements\adapters\UserAdapter
- Since
- 5.12.0
Default elements.* behavior for an element type.
A subclass must define {@see \craft\mcp\elements\handle()}, {@see \craft\mcp\elements\elementType()}, and {@see \craft\mcp\elements\updateAttributesSchema()}. It can opt into creation by defining {@see \craft\mcp\elements\createAttributesSchema()}, and override any other method to add type-specific rules.
Protected Properties ​
| Property | Description |
|---|---|
| elementSerializer | |
| lifecycle |
elementSerializer ​
- Default value
null
lifecycle ​
- Default value
null
Public Methods ​
| Method | Description |
|---|---|
| __construct() | |
| canDelete() | |
| canView() | |
| create() | |
| createUnpublishedDraft() | |
| duplicate() | |
| elementType() | |
| fieldSchemaElement() | |
| find() | |
| handle() | Returns the type value MCP clients pass to select this element type, such as entries. |
| listQuery() | |
| prepareValidation() | |
| schema() | |
| serialize() | |
| update() |
__construct() ​
Arguments ​
$elementSerializer$lifecycle
canDelete() ​
Arguments ​
$actor$element
canView() ​
Arguments ​
$actor$element
create() ​
Arguments ​
$attributes$fields$actor
createUnpublishedDraft() ​
Arguments ​
$attributes$fields$actor$draftName$draftNotes
duplicate() ​
Arguments ​
$element$mode
fieldSchemaElement() ​
Arguments ​
$element$context$actor
find() ​
Arguments ​
$id$uid$siteId
listQuery() ​
Arguments ​
$actor
prepareValidation() ​
Arguments ​
$element$attributes$fields$actor
schema() ​
serialize() ​
Arguments ​
$element$fields$summary
update() ​
Arguments ​
$element$attributes$fields$actor
Protected Methods ​
| Method | Description |
|---|---|
| authorizeSave() | |
| createAttributesSchema() | Returns the JSON Schema for attributes elements.create accepts, or null if it cannot create this type. |
| criteriaProperties() | Returns type-specific criteria properties, added to Craft's common element query criteria. |
| duplicateModes() | |
| fieldSchemaContextSchema() | Returns the JSON Schema for the context that selects a new element's field layout, or null if the type has one field layout. |
| findQuery() | Returns the query find() loads an element with. |
| newElement() | Returns a new, unsaved element. |
| notes() | Returns guidance for MCP clients about this type. |
| populate() | Applies validated attributes and custom field values to an element. |
| prepareCreate() | Returns a new element populated with the given values, after authorizing the actor to save it. |
| save() | |
| saveElement() | Saves an element as the acting user and returns the saved element, which may be a new draft. |
| saveFailed() | |
| setFieldValues() | Sets custom field values given in the format elements.field-schema describes. |
| updateAttributesSchema() | Returns the JSON Schema for attributes elements.update and elements.validate accept. |
authorizeSave() ​
Arguments ​
$actor$element
createAttributesSchema() ​
Returns the JSON Schema for attributes elements.create accepts, or null if it cannot create this type.
Returns ​
array<string,mixed>, null
criteriaProperties() ​
Returns type-specific criteria properties, added to Craft's common element query criteria.
Returns ​
array<string,array<string,mixed>>
duplicateModes() ​
Returns ​
list<string>
fieldSchemaContextSchema() ​
Returns the JSON Schema for the context that selects a new element's field layout, or null if the type has one field layout.
Returns ​
array<string,mixed>, null
findQuery() ​
Returns the query find() loads an element with.
newElement() ​
Returns a new, unsaved element.
Arguments ​
$context(array<string,mixed>) – Values matching thefieldSchemaContextschema, or[]forelements.create.$actor
notes() ​
Returns guidance for MCP clients about this type.
Returns ​
list<string>
populate() ​
Applies validated attributes and custom field values to an element.
Arguments ​
$element$attributes(array<string,mixed>)$fields(array<string,mixed>)$actor
prepareCreate() ​
Returns a new element populated with the given values, after authorizing the actor to save it.
Arguments ​
$attributes(array<string,mixed>)$fields(array<string,mixed>)$actor
save() ​
Arguments ​
$element$actor
Returns ​
array{element: array<string,mixed>}, array<string,mixed>
saveElement() ​
Saves an element as the acting user and returns the saved element, which may be a new draft.
Arguments ​
$element$actor
saveFailed() ​
Arguments ​
$element
setFieldValues() ​
Sets custom field values given in the format elements.field-schema describes.
Arguments ​
$element$fields(array<string,mixed>)
updateAttributesSchema() ​
Returns the JSON Schema for attributes elements.update and elements.validate accept.
Only declared properties are accepted.
Returns ​
array<string,mixed>