You are here

class LlamaContextualAndButton in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/ckeditor/tests/modules/src/Plugin/CKEditorPlugin/LlamaContextualAndButton.php \Drupal\ckeditor_test\Plugin\CKEditorPlugin\LlamaContextualAndButton

Defines a "LlamaContextualAndButton" plugin, with a contextually OR toolbar builder-enabled "llama" feature.

Plugin annotation


@CKEditorPlugin(
  id = "llama_contextual_and_button",
  label = @Translation("Contextual Llama With Button")
)

Hierarchy

Expanded class hierarchy of LlamaContextualAndButton

File

core/modules/ckeditor/tests/modules/src/Plugin/CKEditorPlugin/LlamaContextualAndButton.php, line 20

Namespace

Drupal\ckeditor_test\Plugin\CKEditorPlugin
View source
class LlamaContextualAndButton extends Llama implements CKEditorPluginContextualInterface, CKEditorPluginButtonsInterface, CKEditorPluginConfigurableInterface {

  /**
   * {@inheritdoc}
   */
  public function isEnabled(Editor $editor) {

    // Automatically enable this plugin if the Strike button is enabled.
    $settings = $editor
      ->getSettings();
    foreach ($settings['toolbar']['rows'] as $row) {
      foreach ($row as $group) {
        if (in_array('Strike', $group['items'])) {
          return TRUE;
        }
      }
    }
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function getButtons() {
    return [
      'Llama' => [
        'label' => t('Insert Llama'),
      ],
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getFile() {
    return $this->moduleList
      ->getPath('ckeditor_test') . '/js/llama_contextual_and_button.js';
  }

  /**
   * {@inheritdoc}
   */
  public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {

    // Defaults.
    $config = [
      'ultra_llama_mode' => FALSE,
    ];
    $settings = $editor
      ->getSettings();
    if (isset($settings['plugins']['llama_contextual_and_button'])) {
      $config = $settings['plugins']['llama_contextual_and_button'];
    }
    $form['ultra_llama_mode'] = [
      '#title' => t('Ultra llama mode'),
      '#type' => 'checkbox',
      '#default_value' => $config['ultra_llama_mode'],
    ];
    return $form;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CKEditorPluginInterface::getConfig public function Returns the additions to CKEDITOR.config for a specific CKEditor instance. 7
CKEditorPluginInterface::getDependencies public function Returns a list of plugins this plugin requires. 2
CKEditorPluginInterface::getLibraries public function Returns a list of libraries this plugin requires. 2
CKEditorPluginInterface::isInternal public function Indicates if this plugin is part of the optimized CKEditor build. 2
LlamaContextualAndButton::getButtons public function Returns the buttons that this plugin provides, along with metadata. Overrides CKEditorPluginButtonsInterface::getButtons
LlamaContextualAndButton::getFile public function Returns the Drupal root-relative file path to the plugin JavaScript file. Overrides CKEditorPluginInterface::getFile
LlamaContextualAndButton::isEnabled public function Checks if this plugin should be enabled based on the editor configuration. Overrides CKEditorPluginContextualInterface::isEnabled
LlamaContextualAndButton::settingsForm public function Returns a settings form to configure this CKEditor plugin. Overrides CKEditorPluginConfigurableInterface::settingsForm
PluginInspectionInterface::getPluginDefinition public function Gets the definition of the plugin implementation. 4
PluginInspectionInterface::getPluginId public function Gets the plugin_id of the plugin instance. 2