View source  
  <?php
namespace Drupal\gutenberg\Plugin\Editor;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\gutenberg\GutenbergPluginManager;
use Drupal\gutenberg\Controller\UtilsController;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Render\RendererInterface;
use Drupal\editor\Plugin\EditorBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\editor\Entity\Editor;
use Symfony\Component\DependencyInjection\ContainerInterface;
class Gutenberg extends EditorBase implements ContainerFactoryPluginInterface {
  
  protected $moduleHandler;
  
  protected $languageManager;
  
  protected $gutenbergPluginManager;
  
  protected $renderer;
  
  public function __construct(array $configuration, $plugin_id, $plugin_definition, GutenbergPluginManager $gutenberg_plugin_manager, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager, RendererInterface $renderer) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->gutenbergPluginManager = $gutenberg_plugin_manager;
    $this->moduleHandler = $module_handler;
    $this->languageManager = $language_manager;
    $this->renderer = $renderer;
  }
  
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('plugin.manager.gutenberg.plugin'), $container
      ->get('module_handler'), $container
      ->get('language_manager'), $container
      ->get('renderer'));
  }
  
  public function getDefaultSettings() {
    return [
      'plugins' => [
        'language' => [
          'language_list' => 'un',
        ],
      ],
    ];
  }
  
  public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {
    
    $form['plugin_settings'] = [
      '#type' => 'vertical_tabs',
      '#title' => $this
        ->t('Gutenberg plugin settings'),
      '#attributes' => [
        'id' => 'gutenberg-plugin-settings',
      ],
    ];
    $this->gutenbergPluginManager
      ->injectPluginSettingsForm($form, $form_state, $editor);
    if (count(Element::children($form['plugins'])) === 0) {
      unset($form['plugins']);
      unset($form['plugin_settings']);
    }
    return $form;
  }
  
  public function getLangcodes() {
    return [
      'en' => 'en',
    ];
  }
  
  public function getJsSettings(Editor $editor) {
    $config = \Drupal::service('config.factory')
      ->getEditable('gutenberg.settings');
    $node = \Drupal::routeMatch()
      ->getParameter('node');
    if (!$node) {
      $route_match = \Drupal::service('current_route_match');
      if (!$route_match
        ->getParameter('node_type')) {
        return;
      }
      $node_type = $route_match
        ->getParameter('node_type')
        ->get('type');
    }
    else {
      $node_type = $node->type
        ->getString();
    }
    $blocks_settings = UtilsController::getBlocksSettings();
    $settings = [
      'contentType' => $node_type,
      'allowedBlocks' => $config
        ->get($node_type . '_allowed_blocks'),
      'blackList' => $blocks_settings['blacklist'],
    ];
    return $settings;
  }
  
  public function getLibraries(Editor $editor) {
    $libraries = [
      'gutenberg/edit-node',
      
      'gutenberg/g-media-attributes',
      'gutenberg/blocks-edit',
      'gutenberg/drupal-blocks',
    ];
    return $libraries;
  }
  
  public function buildToolbarJsSetting(Editor $editor) {
    $toolbar = [];
    return $toolbar;
  }
  
  public function buildContentsCssJsSetting(Editor $editor) {
    return [];
  }
}