@alessandro1992ma Sorry for the late reply. I was a bit busy.
Now I had a closer look and I was able to reproduce your setup - with a solution. But first: I was wrong. The plugin wasn’t renamed to cpasset
. I think, it was renamed from assetpath
to cpassetpath
around a year ago. Sorry for the confusion.
The problem is, that the cpassetpath plugin doesn’t have a button specified. I didn’t notice that, because I normally use a custom asset plugin when I use Cockpit with CpMultiplane . I also use the EditorFormats addon to copy my settings to new projects so I don’t have to think about it anymore.
Solution:
Load a custom js file. I named mine wysiwyg-asset-button.js
and saved it in /config
. Load it via /config/bootstrap.php
if (COCKPIT_ADMIN_CP) {
$app->helper('admin')->addAssets('#config:wysiwyg-asset-button.js');
}
Content of /config/wysiwyg-asset-button.js
:
App.$(document).on('init-wysiwyg-editor', function(e, editor) {
editor.addButton('assetpath', {
icon: 'image',
tooltip: App.i18n.get('Insert Asset (Assets)'),
onclick: function(){
App.assets.select(function(assets){
if (Array.isArray(assets) && assets[0]) {
var asset = assets[0], content;
if (asset.mime.match(/^image\//)) {
content = '<img src="' + ASSETS_URL+asset.path + '" alt="">';
} else {
content = '<a href="' + ASSETS_URL+asset.path + '">'+asset.title+'<a>';
}
editor.insertContent(content);
}
});
},
stateSelector: 'img' // highlight toolbar icon when image is selected
});
});
Now you can use assetpath
in your toolbar. Side note: There was a typo in your second example - use plugins
instead of plugin
.
{
"editor": {
"plugins": "cpassetpath",
"toolbar": "undo redo | formatselect | bold italic underline | bullist numlist indent outdent | link unlink | assetpath",
"formats": {
"underline": {
"inline": "u",
"exact": true
}
},
"block_formats": "Paragrafo=p;Titolo 1=h1;Titolo 2=h2;Titolo 3=h3;Titolo 4=h4;",
"contextmenu": false,
"entity_encoding": "raw",
"forced_root_block": "p",
"menubar": false
}
}
It also works with the EditorFormats addon.
This functionality should be added to the core, so you may have to remove that modification with an upcoming cockpit release.
Resources:
editor.addMenuItem('assetpath', {
icon: 'image',
text: App.i18n.get('Insert Asset (Assets)'),
onclick: function(){
App.assets.select(function(assets){
if (Array.isArray(assets) && assets[0]) {
var asset = assets[0], content;
if (asset.mime.match(/^image\//)) {
content = '<img src="' + ASSETS_URL+asset.path + '" alt="">';
} else {
content = '<a href="' + ASSETS_URL+asset.path + '">'+asset.title+'<a>';
}
editor.insertContent(content);
}
});
This file has been truncated. show original
media: {
select: function (callback, options) {
if (!App.$data.acl.finder) return;
callback = callback || function () { };
options = App.$.extend({
previewfiles: false,
pattern: '*',
typefilter: '',
path: false,
selected: []
}, options);
var selected = [], dialog = UIkit.modal.dialog([
'<div>',
'<div class="uk-modal-header uk-text-large">' + App.i18n.get('Select file') + '</div>',
'<cp-finder path="' + (options.path || '') + '" typefilter="' + (options.typefilter || '') + '" modal="true"></cp-finder>',
This file has been truncated. show original