Robin S Posted September 14, 2017 Share Posted September 14, 2017 Just something I was trying out recently that might be useful to someone... With the following hook added to /site/ready.php you can adjust the CKEditor toolbar that a particular role gets for a particular field. Use the name of your CKEditor field in the hook condition. $this->addHookBefore('Field(name=my_ckeditor_field)::getInputfield', function(HookEvent $event) { $field = $event->object; // Define toolbar for a particular role if($this->user->hasRole('editor')) $field->toolbar = 'Format, Bold, Italic, -, NumberedList, BulletedList, Outdent, Indent'; }); Or what I find useful on some sites is adding extra toolbar buttons for superuser only that you don't trust editors to use. $this->addHookBefore('Field(name=my_ckeditor_field)::getInputfield', function(HookEvent $event) { $field = $event->object; // Add extra buttons for superuser only if($this->user->isSuperuser()) $field->toolbar .= ', Table, TextColor'; }); You could use the same technique to selectively define other CKEditor settings such as 'stylesSet', 'customOptions', 'extraPlugins', etc. 18 1 Link to comment Share on other sites More sharing options...
adrian Posted September 14, 2017 Share Posted September 14, 2017 Very nice! 2 Link to comment Share on other sites More sharing options...
abmcr Posted September 19, 2017 Share Posted September 19, 2017 Thank you!!! very nice 1 Link to comment Share on other sites More sharing options...
tpr Posted September 19, 2017 Share Posted September 19, 2017 This is actually so useful that I need to add to AOS (if you don't mind) Removing toolbar items is easy with your code but AOS may add extra buttons via CKEditor plugins. I found out that listing them in "removePlugins" is enough, so this can be used to remove extra plugins with ease: $this->addHookBefore('Field(inputfieldClass=InputfieldCKEditor)::getInputfield', function(HookEvent $event) { // do not show modified data on Field edit page if ($this->wire('process') != 'ProcessPageEdit') { return; } $field = $event->object; if($this->wire('user')->hasRole('editor')) { $field->toolbar = 'Bold, Italic'; $field->removePlugins = 'div, justify'; // plugins to remove $field->formatTags = 'p;h2;h3;h4'; // allowed format tags, separated with semicolon } }); 6 1 Link to comment Share on other sites More sharing options...
Robin S Posted September 19, 2017 Author Share Posted September 19, 2017 2 hours ago, tpr said: This is actually so useful that I need to add to AOS (if you don't mind) Sure, be my guest. 2 Link to comment Share on other sites More sharing options...
AndréPortuga Posted March 19, 2020 Share Posted March 19, 2020 On 9/14/2017 at 5:16 AM, Robin S said: Just something I was trying out recently that might be useful to someone... With the following hook added to /site/ready.php you can adjust the CKEditor toolbar that a particular role gets for a particular field. Use the name of your CKEditor field in the hook condition. $this->addHookBefore('Field(name=my_ckeditor_field)::getInputfield', function(HookEvent $event) { $field = $event->object; // Define toolbar for a particular role if($this->user->hasRole('editor')) $field->toolbar = 'Format, Bold, Italic, -, NumberedList, BulletedList, Outdent, Indent'; }); Or what I find useful on some sites is adding extra toolbar buttons for superuser only that you don't trust editors to use. $this->addHookBefore('Field(name=my_ckeditor_field)::getInputfield', function(HookEvent $event) { $field = $event->object; // Add extra buttons for superuser only if($this->user->isSuperuser()) $field->toolbar .= ', Table, TextColor'; }); You could use the same technique to selectively define other CKEditor settings such as 'stylesSet', 'customOptions', 'extraPlugins', etc. Hi. I'm new with processwire. How can I use embed using CKEditor? Is there a way? I don't know why using the youtube/vimeo module didn't work. Link to comment Share on other sites More sharing options...
dragan Posted March 20, 2020 Share Posted March 20, 2020 16 hours ago, AndréPortuga said: I don't know why using the youtube/vimeo module didn't work. This one? https://modules.processwire.com/modules/textformatter-video-embed/ Did you actually set your CKE field(s) to use that textformatter? ("details" tab in field settings). Just installing that module won't do much. Link to comment Share on other sites More sharing options...
AndréPortuga Posted March 24, 2020 Share Posted March 24, 2020 On 3/20/2020 at 8:50 AM, dragan said: This one? https://modules.processwire.com/modules/textformatter-video-embed/ Did you actually set your CKE field(s) to use that textformatter? ("details" tab in field settings). Just installing that module won't do much. it has to be in a <p> tag. Now it worked, thank you Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now