Issue #3732Opened August 27, 2021by aliibrahim1230 reactions

BUG: comment component type do not support adding traits

Question

i am working on a script that add a trait on all the component type , but the comment type do not have the prototype object. code

        ddw = editor.DomComponents.getTypes();
	
	 for (let i = 0; i < ddw.length; i++) {
	
	ddq = ddw[i].id;
	editor.DomComponents.addType(ddq, {
    model: editor.DomComponents.getType(ddq).model.extend({
      defaults: Object.assign({}, editor.DomComponents.getType(ddq).model.prototype.defaults, {
        
        traits: editor.DomComponents.getType(ddq).model.prototype.defaults.traits.concat([
          'hallo'
        ])
      })
    })
	
    view: editor.DomComponents.getType('text').view
	 });}

Answers (3)

aliibrahim123August 27, 20210 reactions

@artf

artfAugust 29, 20210 reactions

Don't use model.extend/view.extend, those are part of the old API. This is an example of how properly extend traits on all components

const { Components } = editor;
Components.getTypes().forEach(({ id, model }) => {
    Components.addType(id, {
        model: {
            defaults: {
              traits: [ ...model.getDefaults().traits, 'new-trait', ]
            },
        },
    })
});

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.