You are here

EmbedInsertCommand.php in Embed 8

Namespace

Drupal\embed\Ajax

File

src/Ajax/EmbedInsertCommand.php
View source
<?php

namespace Drupal\embed\Ajax;

use Drupal\Core\Ajax\CommandInterface;
use Drupal\Core\Ajax\CommandWithAttachedAssetsTrait;
use Drupal\Core\Ajax\CommandWithAttachedAssetsInterface;

/**
 * AJAX command for inserting an embedded item in an editor.
 *
 * @ingroup ajax
 */
class EmbedInsertCommand implements CommandInterface, CommandWithAttachedAssetsInterface {
  use CommandWithAttachedAssetsTrait;

  /**
   * The content for the matched element(s).
   *
   * Either a render array or an HTML string.
   *
   * @var string|array
   */
  protected $content;

  /**
   * Constructs an EmbedInsertCommand object.
   *
   * @param string|array $content
   *   The content that will be inserted in the matched element(s), either a
   *   render array or an HTML string.
   */
  public function __construct($content) {
    $this->content = $content;
  }

  /**
   * {@inheritdoc}
   */
  public function render() {
    return [
      'command' => 'embed_insert',
      'data' => $this
        ->getRenderedContent(),
    ];
  }

}

Classes

Namesort descending Description
EmbedInsertCommand AJAX command for inserting an embedded item in an editor.