function DrupalUploadImageImce::isEnabled in CKEditor Upload Image 8
Same name and namespace in other branches
- 8.2 src/Plugin/CKEditorPlugin/DrupalUploadImageImce.php \Drupal\ckeditor_uploadimage\Plugin\CKEditorPlugin\DrupalUploadImageImce::isEnabled()
Checks if this plugin should be enabled based on the editor configuration.
The editor's settings can be retrieved via $editor->getSettings().
Parameters
\Drupal\editor\Entity\Editor $editor: A configured text editor object.
Return value
bool
Overrides CKEditorPluginContextualInterface::isEnabled
File
- src/
Plugin/ CKEditorPlugin/ DrupalUploadImageImce.php, line 49 - Contains \Drupal\ckeditor_uploadimage\Plugin\CKEditorPlugin\DrupalUploadImageImce.
Class
- DrupalUploadImageImce
- Defines the "templates" plugin.
Namespace
Drupal\ckeditor_uploadimage\Plugin\CKEditorPluginCode
function isEnabled(Editor $editor) {
$has_access = \Drupal::currentUser()
->hasPermission('use ckeditor_uploadimage');
if (!$editor
->hasAssociatedFilterFormat() || !$has_access) {
return FALSE;
}
// Automatically enable this plugin if the text format associated with this
// text editor uses the filter_align or filter_caption filter and the
// ImceImage button is enabled.
$format = $editor
->getFilterFormat();
if ($format
->filters('filter_align')->status || $format
->filters('filter_caption')->status) {
$enabled = FALSE;
$settings = $editor
->getSettings();
foreach ($settings['toolbar']['rows'] as $row) {
foreach ($row as $group) {
foreach ($group['items'] as $button) {
if ($button === 'ImceImage') {
$enabled = TRUE;
}
}
}
}
return $enabled;
}
return FALSE;
}