AsgardCMS gives you the ability to hook into different part of the application. This lets you change data before it's used somewhere else, or any other feature that can take advantage of hookable events.
To hook into those hooks you can create a listener class that is set to listen on the event you require. All events ending with IsCreating and IsUpdating across module implementing the EntityIsChanging interface.
In those events you have access to the following methods:
getAttributes(): Will return the current attributes of the entity
getAttribute('name', 'default'): Will return the name attribute
setAttributes(): Will set your given attributes
getOriginal(): Will return the original attributes, untouched by other listeners. Optional parameter can be used to get a specific original key
The IsUpdating hooks will usually also have a method to get the entity being updated.
setEditorClass($editorClass): set which class to use on the textarea element
setEditorCssPartial($editorCssPartial): in case you favorite editor requires custom css, you can provide a partial to do that here. Remember to use the push('css-stack') in that partial.
getEditorClass(): returns the editor class
getEditorJsPartial(): get the js partial name
getEditorCssPartial(): get the css partial name
These methods will suffice to most needs of custom wywisyg editors. However, if your editor requires more than just the textarea field, you can overwrite the laravel component completely and use your own. It is probably a good idea to copy the existing components to have something to start with.
When you've created your own components, you can set them by using this API on the EditorIsRendering event:
getI18nComponentName(): Get the component name for the translatable textarea
setI18nComponentName($componentName): Set the component name for the translatable textarea
getComponentName(): Get the component name for the textarea
setComponentName($componentName): Set the component name for the textarea
Using your new editor
You can change which event listener is used by changing the asgard.core.core.wysiwyg-handler configuration option.
AsgardCMS comes with the following options built-in:
If you do choose the markdown editor, you might wonder how to parse and render the markdown, thankfully there's a hook for that: ContentIsRendering. AsgardCMS also comes with a ready to use event listener to render markdown using league/commonmark: RenderMarkdown. Simply use this listener on the ContentIsRendering event and you're good to go.