Prevent editing some components
I would like to prevent users from editing the internal components of specific components.
IE lets say I have an element called Drupal-Block
<div data-block>
... html inside ..
</div>
I want to prevent the users from editing the ... html inside... bit
Are you aware already of data-gjs-* attributes?
eg.
<div data-gjs-editable="false" data-gjs-removable="false" ...>
... html inside ..
</div>
hmm, Where in the workflow would I add this. In my case, I am loading the template information via a remote store. Could I add it during that, or can a add it on a editor.init callback.
I tried adding it manually, but was still able to edit the inner elements.
this attributes data-gjs-editable="false" data-gjs-removable="false" only works for the current selected element not for their childs, @cmcintosh I also tried put manually but it only works when I set this attributes on every child elements, like this:

Yeah, @MichaelKlemersson is right currently you have to set them manually on any element. Another trick would be to update all children via model
const updateAll = model => {
model.set({editable: false, ...});
model.get('components').each(model => updateAll(model));
}
updateAll(component);
But what I think would be the best it's some kind of property which propagates (suggestions for a better term are welcome) properties from the parent to its children, eg.
<div data-gjs-editable="false" data-gjs-propagate="['editable', ...]">
<!-- this will be not editable too and the same for its children -->
<div>...</div>
<!-- possibility to overwrite and 'break' the chain -->
<div data-gjs-editable="true" data-gjs-propagate=""></div>
</div>
what do you think?
Yes i think that the propagation idea is great. To be clear the reason im looking for this is im building out a module for Drupal 8 that will allow creating themes via the GrapeJS tool. In Drupal you have elements called Blocks, and my thought was to block of editing of those on the Main editor, and instead have a popup editor to edit them and allow reusing those across various pages.
This is due to how Drupal renders content via PHP and thus I need to convert the html to php variables when storing the template into a twig file.
+1 on the propagation idea
@cmcintosh It's a great idea, I vote for propagates and this will be really helpful using in a trait, so se could toggle this functionality ;)
thanks for the feedback guys, I'll put it on the Roadmap
@artf can you expand on the first option on your previous comment, ''' const updateAll = model => { model.set({editable: false, ...}); model.get('components').each(model => updateAll(model)); } updateAll(component); '''
I am not familiar with what framework your using so am still picking up how its supposed to work (actually dont know what framwork you are using and have been leaning mostly on jquery)
He is using backbone js, if I'm not wrong.
Thanks, looks like time for me to learn a new framework ;)
Out of curiosity. What's preventing from looking to see if any parent elements have the "data-gjs-editable" attribute to prevent a the current element from being editable?
nothing, I had thought that would be the ideal path. Not totally sure to implement it yet
An example you can use in the demo
- Select an element (eg. some section)
- Execute this in console
editor.getSelected().append(`
<div data-gjs-removable="false" data-gjs-draggable="false" data-gjs-propagate='["removable", "draggable"]' style="color:blue">
<div>Comp01</div>
<div>
<div>Comp11</div>
<div data-gjs-stop="1" data-gjs-removable="true" data-gjs-draggable="true" data-gjs-propagate='["stop"]' style="color:red">
<div>Comp21</div>
<div>Comp22</div>
</div>
<div>
<div>Comp31</div>
<div>Comp32</div>
</div>
</div>
<div>Comp03</div>
</div>
`)
Thanks, ill look at this tomorrow ;)
@artf - Will there be a propagate html attribute? Like what you detailed below?
<div data-gjs-editable="false" data-gjs-propagate="['editable', ...]">
@cmcintosh How far did you get into your Drupal 8 Module as I am working to do the same in Drupal 7? Thanks.
@AustinTBiggs is already there
be careful because ['editable', ...] is not a valid JSON (you have to use double quotes for keys), therefore data-gjs-propagate='["editable", ...]'
@Coyote6 I am still working on things for this. Was busy on other things, but am now back at it.
@cmcintosh awesome. I completely understand how that goes. I have been updating my repository that I left a link to on your drupal project once I found it. I am looking forward to getting a good solid version working.