You are here

public function Gutenberg::getJsSettings in Gutenberg 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/Editor/Gutenberg.php \Drupal\gutenberg\Plugin\Editor\Gutenberg::getJsSettings()

Get javascript settings.

Parameters

\Drupal\editor\Entity\Editor $editor: A configured text editor object.

File

src/Plugin/Editor/Gutenberg.php, line 150

Class

Gutenberg
Defines a Gutenberg-based text editor for Drupal.

Namespace

Drupal\gutenberg\Plugin\Editor

Code

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;
}