Skip to content

Instantly share code, notes, and snippets.

@jesseschutt
Created January 20, 2016 01:31
Show Gist options
  • Save jesseschutt/f24f931ca4520563809f to your computer and use it in GitHub Desktop.
Save jesseschutt/f24f931ca4520563809f to your computer and use it in GitHub Desktop.
Steps for Saving a Custom ElementType in Craft CMS
1. Create a model and populate its data (may or may not have an ID yet)
2. Populate the record from the model.
3. Validate the record and add any errors found to the model.
4. If the model and record are valid, save the model with the `craft()->elements->saveElement($model)` which, if successful, will place an ID on the model if there was none.
5. If the model saved successfully with the element service, add the model's ID to the record and save the record.
6. This results in the same ID being shared in the main `craft_elements` table , and your own records table.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment