How do I extend a content type in XP 6.0?

Enonic version: 6.0.0
OS: Windows

Hi,

I am trying to create a formbuilder-app in XP, and plan to implement input types as different content types. As part of this, I thought I would create a base-input type (abstract), with inputs for label, id, etc, and extend this for the type-specific content-types.

However, the sub-types doesn’t get the super-type’s input fields. What, then is the point of the super-type?
Is it only possible to extend built-in content types?

I realize mixins could solve part of my problem, but I was kind of hoping to test extending content types as well… :smile:

If this doesn’t work the way I was hoping, is it possible this might become a feature eventually?

- Vegard

Hi Vegard!

The “supertype” is more like a “handler/processor” - that will handle specific processing of each type, i.e. the structured one understands regular content type definitions, media expects at least one attachment etc. So this is not inheritance. We’ll look into that naming later. Currently the “supertypes” are not pluggable.

So, the way to go is mixins.

The reasion we don’t support inheritance is simply that when inheriting both data-type and form this is not a simple matter at all. So we rather went for “horizontal inheritance” with the mixins instead.

You’ll see many cool features built on mixins in the future.

Ok. I think it would be a nice feature, especially because mixins appear as a separate part of the form in the content type using them, but I understand that there might be technical reasons for not doing so.

However - have you considered removing the border around mixin input fields or at least making it optional?

I would really like to create a content type that looks like it has been made as one, but where I can re-use input fields from super-classes or mixins. Right now, if there are only small differences between the content types, and the mixin contains many fields, the actual unique input fields are separated from the rest, possibly confusing the user/editor.

Hmmm. I guess you think about extra data? Did you know mixins can be used inline too? Think this is what you’re looking for?

<content-type>
  <display-name>Using mixins</display-name>
  <super-type>base:structured</super-type>
  <form>
    <field-set name="basic">
      <label>Status</label>
      <items>
        <inline mixin="us-address"/>
      </items>
    </field-set>
  </form>
  <x-data mixin="menu-item"/>
</content-type>

You can see both ways to use mixins in the example above. The <inline mixin="us-address"/> will appear the same as if the inputs where written directly into the content type.

1 Like

Do I have to use field-sets? I have normally skipped them for content types with few input elements, but mixins seem to “require” being used inside a field-set. At least they generate the border around if they are not used in a field set.

An example:

<content-type>
  <display-name>Input: Range</display-name>
  <content-display-name-script>$('label')</content-display-name-script>
  <super-type>base:structured</super-type>
  <is-abstract>false</is-abstract>
  <is-final>true</is-final>
  <allow-child-content>true</allow-child-content>
  <form>
    <inline mixin="input-mixin"/>
    <input name="minValue" type="Long">
      <label>Minimum value</label>
      <occurrences minimum="0" maximum="1"/>
      <config/>
    </input>
    <input name="maxValue" type="Long">
      <label>Maximum value</label>
      <occurrences minimum="0" maximum="1"/>
      <config/>
    </input>
  </form>
</content-type>

Need to see mixin and screenshot too?!

Mixin:

<mixin>
  <display-name>Input common data</display-name>
  <items>
    <item-set name="meta">
      <label>Input common data</label>
      <occurrences minimum="1" maximum="1"/>
      <items>
        <input name="id" type="TextLine">
          <label>Id</label>
          <occurrences minimum="1" maximum="1"/>
          <config/>
        </input>
        <input name="name" type="TextLine">
          <label>Name</label>
          <occurrences minimum="1" maximum="1"/>
          <config/>
        </input>
        <input name="label" type="TextLine">
          <label>Label</label>
          <occurrences minimum="1" maximum="1"/>
          <config/>
        </input>
        <input name="required" type="CheckBox">
          <label>Required</label>
          <occurrences minimum="0" maximum="1"/>
          <config/>
        </input>
      </items>
    </item-set>
  </items>
</mixin>

Screenshot in use:

(I added another custom field for this input after the first post. Not that that should matter.)

Reason you get a frame is the inputSet. This is normally intended for use with occurrence flexibility… Just drop itemSet to drop frame.

The only reason to use an item-set is when you need several inputs to be repeated together. An item-set maximum should never be 1.

Ahhh, I didn’t notice that one. It is probably something which was included in some copy-pasting from another project…
I’ll double-check tonight, but that looks like it will solve it.

Thanks!