/**
  * Checks if the embed button is enabled in an editor configuration.
  *
  * @param \Drupal\embed\EmbedButtonInterface $embed_button
  *   The embed button entity to check.
  * @param \Drupal\editor\EditorInterface $editor
  *   The editor entity to check.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *
  * @throws \Symfony\Component\HttpKernel\Exception\HttpException
  *   When the received Text Editor entity does not use CKEditor. This is
  *   currently only capable of detecting buttons used by CKEditor.
  */
 protected function checkButtonEditorAccess(EmbedButtonInterface $embed_button, EditorInterface $editor)
 {
     if ($editor->getEditor() !== 'ckeditor') {
         throw new HttpException(500, 'Currently, only CKEditor is supported.');
     }
     $has_button = FALSE;
     $settings = $editor->getSettings();
     foreach ($settings['toolbar']['rows'] as $row) {
         foreach ($row as $group) {
             if (in_array($embed_button->id(), $group['items'])) {
                 $has_button = TRUE;
                 break 2;
             }
         }
     }
     return AccessResult::allowedIf($has_button)->addCacheableDependency($embed_button)->addCacheableDependency($editor);
 }
 protected function getButton(EmbedButtonInterface $embed_button)
 {
     return ['id' => $embed_button->id(), 'name' => Html::escape($embed_button->label()), 'label' => Html::escape($embed_button->label()), 'image' => $embed_button->getIconUrl()];
 }
 /**
  * Returns the allowed Entity Embed Display plugins given an embed button and
  * an entity.
  *
  * @param \Drupal\embed\EmbedButtonInterface $embed_button
  *   The embed button.
  * @param \Drupal\Core\Entity\EntityInterface $entity
  *   The entity.
  *
  * @return array
  *   List of allowed Entity Embed Display plugins.
  */
 public function getDisplayPluginOptions(EmbedButtonInterface $embed_button, EntityInterface $entity)
 {
     $plugins = $this->displayPluginManager->getDefinitionOptionsForEntity($entity);
     if ($allowed_plugins = $embed_button->getTypeSetting('display_plugins')) {
         $plugins = array_intersect_key($plugins, array_flip($allowed_plugins));
     }
     natsort($plugins);
     return $plugins;
 }