Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdunogier/89d6997c34fb8a2f4d74 to your computer and use it in GitHub Desktop.
Save bdunogier/89d6997c34fb8a2f4d74 to your computer and use it in GitHub Desktop.

Platform interface/API idea: ContentType/Field mapping for extensions.

My extension does stuff on different content types / fields, and I want my users to be able to easily map their content structure to my needs.

In an extension, instead of getting content types using the ContentTypeService, one could use this other API. It would return something that looks like the expected content type, and it would map the fields.

Note that this is I think very close from what Kaliop's Object Forwarder does.

Example

A controller creates content, and expects a ContentType with the fields title, body and image:

// loadContentType uses the mapping customized by the extension's user
$contentType = $contentTypeThingie->loadContentType('article');

// When setField is called, the mapper uses the mapping configuration to set the actually expected field.
$draft = $contentService->newContentCreateStruct($contentType, 'eng-GB');
$draft->setField('title', $title);
$draft->setField('body', $body);
$draft->setField('image', $image);

Based on the mapping configuration provided by the feature, the content type and field definitions are transparently mapped to values that exist on the system the code is running on. The code will run, and create content, on any system it is installed to. The original code can be re-used, and content types / fields don't need to be adapted to every instance.

(The examples above might not work in real life, as the mapper object might not be given a chance to do the expected mapping.)

Converters could be offered when applicable (textblock => richtext, string => integer, etc).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment