How do I add a trait to all existing component types?
Question
I want to go through all existing component types and add a trait to the model-> defaults and can't figure out how to do this. According to the documentation, I should be able to (in my plugin):
// now - traits that should be on every component - base characteristics that we want to apply
domComponents.getTypes().map(type => {
domComponents.addType(type.id, {
model: {
defaults: {
traits: [
{
label: 'Allow editing in pages',
name: 'allow_editing_in_pages',
type: 'checkbox'
}
]
}
}
})
});
But this overrides the traits array, which removes the existing traits, which isn't what I want. My next step was to try to get the old traits and concat them with my new ones - but I can't figure out how to pull the default traits for each type in order to do this.
How can I append a trait to all (or some) component types?
Answers (1)
@andrewryan1906 for pulling the default traits:
domComponents.getType(type.id).model.prototype.defaults.traits
so your traits definition would be like below:
traits: [
...domComponents.getType(type.id).model.prototype.defaults.traits,
{
label: 'Allow editing in pages',
name: 'allow_editing_in_pages',
type: 'checkbox'
}
]
cheers!
Related Questions and Answers
Continue research with similar issue discussions.
Issue #2741
How to wrap component with text nodes based on trait?
Hello @artf , I'm not sure if this goes here but I can't figure out from the documentation how to update the component model based on a tra...
Issue #913
[Question] Using Style tag instead of css
Hi, I've been taking a look inside of the dom_components, but cant seem to figure out how to manually override the styling aspect. I need a...
Issue #1695
Adding new trait to Video component
I want to add a new trait for existing VIDEO '' component. I follow the docs and I didn't find what I want. Now I got the new trait added t...
Issue #1021
[QUESTION] Style Manager sectors
Hey @artf , due to the lack of documentation I have a hard time figuring out, how to add component settings (traits ) to the Style Manager...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.