You are here

public function CkeditorTableSelection::isEnabled in CKEditor Table Selection 8

Same name and namespace in other branches
  1. 9.1.x src/Plugin/CKEditorPlugin/CkeditorTableSelection.php \Drupal\ckeditor_tableselection\Plugin\CKEditorPlugin\CkeditorTableSelection::isEnabled()
  2. 2.0.x src/Plugin/CKEditorPlugin/CkeditorTableSelection.php \Drupal\ckeditor_tableselection\Plugin\CKEditorPlugin\CkeditorTableSelection::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/CkeditorTableSelection.php, line 48

Class

CkeditorTableSelection
Defines the "Table Selection" plugin.

Namespace

Drupal\ckeditor_tableselection\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
  // Table button is enabled.
  $format = $editor
    ->getFilterFormat();
  if ($format
    ->filters('filter_align')->status || $format
    ->filters('filter_caption')->status) {
    $settings = $editor
      ->getSettings();
    foreach ($settings['toolbar']['rows'] as $row) {
      foreach ($row as $group) {
        foreach ($group['items'] as $button) {
          if ($button === 'Table') {
            return TRUE;
          }
        }
      }
    }
  }
  return FALSE;
}