3 namespace Drupal\embed;
5 use Drupal\Component\Utility\Html;
6 use Drupal\Core\Entity\Query\QueryInterface;
7 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
8 use Drupal\ckeditor\CKEditorPluginBase;
9 use Drupal\editor\Entity\Editor;
10 use Drupal\embed\Entity\EmbedButton;
11 use Symfony\Component\DependencyInjection\ContainerInterface;
13 abstract class EmbedCKEditorPluginBase extends CKEditorPluginBase implements ContainerFactoryPluginInterface {
16 * The embed button query.
18 * @var \Drupal\Core\Entity\Query\QueryInterface
20 protected $embedButtonQuery;
23 * Constructs a Drupal\entity_embed\Plugin\CKEditorPlugin\DrupalEntity object.
25 * @param array $configuration
26 * A configuration array containing information about the plugin instance.
27 * @param string $plugin_id
28 * The plugin_id for the plugin instance.
29 * @param mixed $plugin_definition
30 * The plugin implementation definition.
31 * @param \Drupal\Core\Entity\Query\QueryInterface $embed_button_query
32 * The entity query object for embed button.
34 public function __construct(array $configuration, $plugin_id, $plugin_definition, QueryInterface $embed_button_query) {
35 parent::__construct($configuration, $plugin_id, $plugin_definition);
36 $this->embedButtonQuery = $embed_button_query;
37 if (!empty($plugin_definition['embed_type_id'])) {
38 $this->embedButtonQuery->condition('type_id', $plugin_definition['embed_type_id']);
45 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
50 $container->get('entity.query')->get('embed_button')
57 public function getButtons() {
60 if ($ids = $this->embedButtonQuery->execute()) {
61 $embed_buttons = EmbedButton::loadMultiple($ids);
62 foreach ($embed_buttons as $embed_button) {
63 $buttons[$embed_button->id()] = $this->getButton($embed_button);
70 protected function getButton(EmbedButtonInterface $embed_button) {
72 'id' => $embed_button->id(),
73 'name' => Html::escape($embed_button->label()),
74 'label' => Html::escape($embed_button->label()),
75 'image' => $embed_button->getIconUrl(),
82 public function getLibraries(Editor $editor) {