You are here

class AddStyleSheetCommand in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/ckeditor/src/Ajax/AddStyleSheetCommand.php \Drupal\ckeditor\Ajax\AddStyleSheetCommand

AJAX command to add style sheets to a CKEditor instance.

Hierarchy

Expanded class hierarchy of AddStyleSheetCommand

1 file declares its use of AddStyleSheetCommand
AjaxCssForm.php in core/modules/ckeditor/tests/modules/src/Form/AjaxCssForm.php

File

core/modules/ckeditor/src/Ajax/AddStyleSheetCommand.php, line 10

Namespace

Drupal\ckeditor\Ajax
View source
class AddStyleSheetCommand implements CommandInterface {

  /**
   * The CKEditor instance ID.
   *
   * @var string
   */
  protected $editorId;

  /**
   * The style sheet URLs to add to the CKEditor instance.
   *
   * @var string[]
   */
  protected $styleSheets = [];

  /**
   * AddStyleSheetCommand constructor.
   *
   * @param string $editor_id
   *   The CKEditor instance ID.
   * @param string[] $stylesheets
   *   The style sheet URLs to add to the CKEditor instance.
   */
  public function __construct($editor_id, array $stylesheets = []) {
    $this->editorId = $editor_id;
    $this->styleSheets = $stylesheets;
  }

  /**
   * Adds a style sheet to the CKEditor instance.
   *
   * @param string $stylesheet
   *   The style sheet URL.
   *
   * @return $this
   *   The called object, for chaining.
   */
  public function addStyleSheet($stylesheet) {
    $this->styleSheets[] = $stylesheet;
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function render() {
    return [
      'command' => 'ckeditor_add_stylesheet',
      'editor_id' => $this->editorId,
      'stylesheets' => $this->styleSheets,
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AddStyleSheetCommand::$editorId protected property The CKEditor instance ID.
AddStyleSheetCommand::$styleSheets protected property The style sheet URLs to add to the CKEditor instance.
AddStyleSheetCommand::addStyleSheet public function Adds a style sheet to the CKEditor instance.
AddStyleSheetCommand::render public function Return an array to be run through json_encode and sent to the client. Overrides CommandInterface::render
AddStyleSheetCommand::__construct public function AddStyleSheetCommand constructor.