You are here

function DrupalImageStyle::isEnabled in Inline responsive images 7

Same name and namespace in other branches
  1. 8 src/Plugin/CKEditorPlugin/DrupalImageStyle.php \Drupal\inline_responsive_image\Plugin\CKEditorPlugin\DrupalImageStyle::isEnabled()

File

src/Plugin/CKEditorPlugin/DrupalImageStyle.php, line 63

Class

DrupalImageStyle
Defines the "drupalimagestyle" plugin.

Namespace

Drupal\inline_responsive_image\Plugin\CKEditorPlugin

Code

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;
}