Skip to content

add class extends generate:plugin:ckeditorbutton #4149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Command/Generate/PluginCKEditorButtonCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ function ($class_name) {

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

array_push(
Expand Down
8 changes: 7 additions & 1 deletion src/Generator/PluginCKEditorButtonGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,17 @@ public function generate(array $parameters)
{
$class_name = $parameters['class_name'];
$module = $parameters['module'];

$plugin_id = $parameters['plugin_id'];

$this->renderFile(
'module/src/Plugin/CKEditorPlugin/ckeditorbutton.php.twig',
$this->extensionManager->getPluginPath($module, 'CKEditorPlugin') . '/' . $class_name . '.php',
$parameters
);
$this->renderFile(
'module/src/Plugin/CKEditorPlugin/plugin.php.twig',
drupal_get_path('module', $module) . '/js/Plugin/'. $plugin_id .'/plugin.js',
$parameters
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ use Drupal\editor\Entity\Editor;
*
* @CKEditorPlugin(
* id = "{{ plugin_id }}",
* label = @Translation("{{ label }}")
* label = @Translation("{{ label }}"),
* module = "{{ module }}"
* )
*/
class {{ class_name }} extends CKEditorPluginBase {% endblock %}
Expand All @@ -48,14 +49,19 @@ class {{ class_name }} extends CKEditorPluginBase {% endblock %}
{% endfor %}
];
}
/**
* {@inheritdoc}
*/
public function isEnabled(Editor $editor) {
}

/**
* {@inheritdoc}
*/
public function getFile() {
// Make sure that the path to the plugin.js matches the file structure of
// the CKEditor plugin you are implementing.
return drupal_get_path('module', '{{ module }}') . '/js/plugins/{{ plugin_id }}/plugin.js';
return drupal_get_path('module', '{{ module }}') . '/js/Plugin/{{ plugin_id }}/plugin.js';
}

/**
Expand Down
20 changes: 20 additions & 0 deletions templates/module/src/Plugin/CKEditorPlugin/plugin.php.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* DO NOT EDIT THIS FILE.
* See the following change record for more information,
* https://www.drupal.org/node/2815083
* @preserve
**/
{% for button in buttons %}
CKEDITOR.plugins.add('{{ pligins_id }}', {
init: function( editor ) {
if ( editor.ui.addButton ) {
editor.ui.addButton( '{{ button.name }}', {
label: 'default ckeditor button',
id: '{{ button.name }}',
command: '',
toolbar: '{{ button.name }},10',
} );
}
}
} );
{% endfor %}