Skip to content

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.

View source

Protected Properties ​

PropertyDescription
elementSerializer
lifecycle

elementSerializer ​

Default value
null

View source

lifecycle ​

Default value
null

View source

Public Methods ​

MethodDescription
__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() ​

View source

Arguments ​

  • $elementSerializer
  • $lifecycle

canDelete() ​

View source

Arguments ​

  • $actor
  • $element

canView() ​

View source

Arguments ​

  • $actor
  • $element

create() ​

View source

Arguments ​

  • $attributes
  • $fields
  • $actor

createUnpublishedDraft() ​

View source

Arguments ​

  • $attributes
  • $fields
  • $actor
  • $draftName
  • $draftNotes

duplicate() ​

View source

Arguments ​

  • $element
  • $mode

fieldSchemaElement() ​

View source

Arguments ​

  • $element
  • $context
  • $actor

find() ​

View source

Arguments ​

  • $id
  • $uid
  • $siteId

listQuery() ​

View source

Arguments ​

  • $actor

prepareValidation() ​

View source

Arguments ​

  • $element
  • $attributes
  • $fields
  • $actor

schema() ​

View source

serialize() ​

View source

Arguments ​

  • $element
  • $fields
  • $summary

update() ​

View source

Arguments ​

  • $element
  • $attributes
  • $fields
  • $actor

Protected Methods ​

MethodDescription
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() ​

View source

Arguments ​

  • $actor
  • $element

createAttributesSchema() ​

Returns the JSON Schema for attributes elements.create accepts, or null if it cannot create this type.

View source

Returns ​

array<string,mixed>, null

criteriaProperties() ​

Returns type-specific criteria properties, added to Craft's common element query criteria.

View source

Returns ​

array<string,array<string,mixed>>

duplicateModes() ​

View source

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.

View source

Returns ​

array<string,mixed>, null

findQuery() ​

Returns the query find() loads an element with.

View source

newElement() ​

Returns a new, unsaved element.

View source

Arguments ​

  • $context (array<string,mixed>) – Values matching the fieldSchemaContext schema, or [] for elements.create.
  • $actor

notes() ​

Returns guidance for MCP clients about this type.

View source

Returns ​

list<string>

populate() ​

Applies validated attributes and custom field values to an element.

View source

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.

View source

Arguments ​

  • $attributes (array<string,mixed>)
  • $fields (array<string,mixed>)
  • $actor

save() ​

View source

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.

View source

Arguments ​

  • $element
  • $actor

saveFailed() ​

View source

Arguments ​

  • $element

setFieldValues() ​

Sets custom field values given in the format elements.field-schema describes.

View source

Arguments ​

  • $element
  • $fields (array<string,mixed>)

updateAttributesSchema() ​

Returns the JSON Schema for attributes elements.update and elements.validate accept.

Only declared properties are accepted.

View source

Returns ​

array<string,mixed>