sulu-docs
sulu-docs copied to clipboard
Document "Create Custom Content Type"
https://github.com/sulu-io/sulu/issues/451#issuecomment-147306832
Any updates on this? Thank you
No, there are no updates until now...
Can you hint us on a sample implementation of a simple custom content type. Or which classes, template and config files are required to get it done and how to correctly register it to the sulu cms system.
If I look at SingleInternalLink (choose it to avoid naming collisions when searching through the whole project). I can find the following files:
- vendor/sulu/sulu/src/Sulu/Bundle/ContentBundle/Content/Types/SingleInternalLink.php // Content type class that extens Sulu\Component\Content\SimpleContentType
- vendor/sulu/sulu/src/Sulu/Bundle/ContentBundle/Resources/public/js/components/single-internal-link/main.js // A class that handles some sulu admin form field behaviours, in this case the link selection. This is (seems to be) not necessarily required for any fieldtype, but probably useful in many "custom content type" use cases.
- vendor/sulu/sulu/src/Sulu/Bundle/ContentBundle/Resources/config/content_types.xml // This seems to be needed to register the content types
There are 4 points you have to do.
- Create a tagged service (
sulu.content.type
) which implements theContentTypeInterface
or extendSimpleContentType
. - Create an aura-component which implements the UI for the
ContentType
(seevendor/sulu/sulu/src/Sulu/Bundle/ContentBundle/Resources/public/js/components/single-internal-link/main.js
) - Create a data-type (see
vendor/sulu/sulu/src/Sulu/Bundle/ContentBundle/Resources/public/js/validation/types/singleInternalLink.js
) - Create a template (see
vendor/sulu/sulu/src/Sulu/Bundle/ContentBundle/Resources/views/Template/content-types/single_internal_link.html.twig
) which starts the component.
Example implementation can be found here: https://github.com/sulu/ExampleNewsBundle/pull/14
An example implementation for Sulu 2.0 is available in the sulu-demo repository: https://github.com/sulu/sulu-demo/pull/66