sulu-docs icon indicating copy to clipboard operation
sulu-docs copied to clipboard

Document "Create Custom Content Type"

Open joemoe opened this issue 8 years ago • 6 comments

https://github.com/sulu-io/sulu/issues/451#issuecomment-147306832

joemoe avatar Oct 12 '15 07:10 joemoe

Any updates on this? Thank you

SalvatorePollaci avatar Dec 09 '16 09:12 SalvatorePollaci

No, there are no updates until now...

danrot avatar Dec 09 '16 12:12 danrot

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

cioddi avatar Apr 07 '17 16:04 cioddi

There are 4 points you have to do.

  1. Create a tagged service (sulu.content.type) which implements the ContentTypeInterface or extend SimpleContentType.
  2. Create an aura-component which implements the UI for the ContentType (see vendor/sulu/sulu/src/Sulu/Bundle/ContentBundle/Resources/public/js/components/single-internal-link/main.js)
  3. Create a data-type (see vendor/sulu/sulu/src/Sulu/Bundle/ContentBundle/Resources/public/js/validation/types/singleInternalLink.js)
  4. 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.

wachterjohannes avatar Apr 10 '17 05:04 wachterjohannes

Example implementation can be found here: https://github.com/sulu/ExampleNewsBundle/pull/14

alexander-schranz avatar Jul 14 '17 13:07 alexander-schranz

An example implementation for Sulu 2.0 is available in the sulu-demo repository: https://github.com/sulu/sulu-demo/pull/66

niklasnatter avatar Oct 20 '20 14:10 niklasnatter