Skip to content

Commit 173a51d

Browse files
gilbertomangonesenzolutions
authored andcommitted
add class extends generate:plugin:ckeditorbutton (#4149)
* add class extends generate:plugin:ckeditorbutton * class extends in generate:plugin:ckeditorbutton * fix error js in generate:plugin:ckeditorbutton * Fix paths and structure plugin Ckeditor
1 parent f26fd9b commit 173a51d

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

src/Command/Generate/PluginCKEditorButtonCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ function ($class_name) {
204204

205205
$buttonIcon = $this->getIo()->ask(
206206
$this->trans('commands.generate.plugin.ckeditorbutton.questions.button-icon-path'),
207-
drupal_get_path('module', $module) . '/js/plugins/' . $plugin_id . '/images/icon.png'
207+
drupal_get_path('module', $module) . '/js/plugin/'.$plugin_id.'/icons/'.$buttonName.'.png'
208208
);
209209

210210
array_push(

src/Generator/PluginCKEditorButtonGenerator.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,17 @@ public function generate(array $parameters)
3535
{
3636
$class_name = $parameters['class_name'];
3737
$module = $parameters['module'];
38-
38+
$plugin_id = $parameters['plugin_id'];
39+
3940
$this->renderFile(
4041
'module/src/Plugin/CKEditorPlugin/ckeditorbutton.php.twig',
4142
$this->extensionManager->getPluginPath($module, 'CKEditorPlugin') . '/' . $class_name . '.php',
4243
$parameters
4344
);
45+
$this->renderFile(
46+
'module/src/Plugin/CKEditorPlugin/plugin.php.twig',
47+
drupal_get_path('module', $module) . '/js/Plugin/'. $plugin_id .'/plugin.js',
48+
$parameters
49+
);
4450
}
4551
}

templates/module/src/Plugin/CKEditorPlugin/ckeditorbutton.php.twig

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ use Drupal\editor\Entity\Editor;
2323
*
2424
* @CKEditorPlugin(
2525
* id = "{{ plugin_id }}",
26-
* label = @Translation("{{ label }}")
26+
* label = @Translation("{{ label }}"),
27+
* module = "{{ module }}"
2728
* )
2829
*/
2930
class {{ class_name }} extends CKEditorPluginBase {% endblock %}
@@ -48,14 +49,19 @@ class {{ class_name }} extends CKEditorPluginBase {% endblock %}
4849
{% endfor %}
4950
];
5051
}
52+
/**
53+
* {@inheritdoc}
54+
*/
55+
public function isEnabled(Editor $editor) {
56+
}
5157

5258
/**
5359
* {@inheritdoc}
5460
*/
5561
public function getFile() {
5662
// Make sure that the path to the plugin.js matches the file structure of
5763
// the CKEditor plugin you are implementing.
58-
return drupal_get_path('module', '{{ module }}') . '/js/plugins/{{ plugin_id }}/plugin.js';
64+
return drupal_get_path('module', '{{ module }}') . '/js/Plugin/{{ plugin_id }}/plugin.js';
5965
}
6066

6167
/**
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* DO NOT EDIT THIS FILE.
3+
* See the following change record for more information,
4+
* https://www.drupal.org/node/2815083
5+
* @preserve
6+
**/
7+
{% for button in buttons %}
8+
CKEDITOR.plugins.add('{{ pligins_id }}', {
9+
init: function( editor ) {
10+
if ( editor.ui.addButton ) {
11+
editor.ui.addButton( '{{ button.name }}', {
12+
label: 'default ckeditor button',
13+
id: '{{ button.name }}',
14+
command: '',
15+
toolbar: '{{ button.name }},10',
16+
} );
17+
}
18+
}
19+
} );
20+
{% endfor %}

0 commit comments

Comments
 (0)