function DrupalImageCaption::isEnabled

Same name in other branches
  1. 9 core/modules/ckeditor/src/Plugin/CKEditorPlugin/DrupalImageCaption.php \Drupal\ckeditor\Plugin\CKEditorPlugin\DrupalImageCaption::isEnabled()

Overrides CKEditorPluginContextualInterface::isEnabled

File

core/modules/ckeditor/src/Plugin/CKEditorPlugin/DrupalImageCaption.php, line 80

Class

DrupalImageCaption
Defines the "drupalimagecaption" plugin.

Namespace

Drupal\ckeditor\Plugin\CKEditorPlugin

Code

public function isEnabled(Editor $editor) {
    if (!$editor->hasAssociatedFilterFormat()) {
        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
    // DrupalImage 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 === 'DrupalImage') {
                        $enabled = TRUE;
                    }
                }
            }
        }
        return $enabled;
    }
    return FALSE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.