class Gutenberg in Gutenberg 8
Same name and namespace in other branches
- 8.2 src/Plugin/Editor/Gutenberg.php \Drupal\gutenberg\Plugin\Editor\Gutenberg
Defines a Gutenberg-based text editor for Drupal.
Plugin annotation
@Editor(
id = "gutenberg",
label = @Translation("Gutenberg"),
supports_content_filtering = TRUE,
supports_inline_editing = TRUE,
is_xss_safe = FALSE,
supported_element_types = {
"textarea"
}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\editor\Plugin\EditorBase implements EditorPluginInterface
- class \Drupal\gutenberg\Plugin\Editor\Gutenberg implements ContainerFactoryPluginInterface
- class \Drupal\editor\Plugin\EditorBase implements EditorPluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of Gutenberg
3 string references to 'Gutenberg'
- example_block.info.yml in modules/
example_block/ example_block.info.yml - modules/example_block/example_block.info.yml
- gutenberg.info.yml in ./
gutenberg.info.yml - gutenberg.info.yml
- gutenberg_cloud.info.yml in modules/
gutenberg_cloud/ gutenberg_cloud.info.yml - modules/gutenberg_cloud/gutenberg_cloud.info.yml
File
- src/
Plugin/ Editor/ Gutenberg.php, line 31
Namespace
Drupal\gutenberg\Plugin\EditorView source
class Gutenberg extends EditorBase implements ContainerFactoryPluginInterface {
/**
* The module handler to invoke hooks on.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/**
* The Gutenberg plugin manager.
*
* @var \Drupal\gutenberg\GutenbergPluginManager
*/
protected $gutenbergPluginManager;
/**
* Drupal\Core\Render\RendererInterface instance.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* Constructs a Gutenberg object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\gutenberg\GutenbergPluginManager $gutenberg_plugin_manager
* The Gutenberg plugin manager.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler to invoke hooks on.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The 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;
}
/**
* {@inheritdoc}
*/
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'));
}
/**
* {@inheritdoc}
*/
public function getDefaultSettings() {
return [
'plugins' => [
'language' => [
'language_list' => 'un',
],
],
];
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {
// Gutenberg plugin settings, if any.
$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;
}
/**
* Returns a list of language codes supported by CKEditor.
*
* @return array
* An associative array keyed by language codes.
*/
public function getLangcodes() {
return [
'en' => 'en',
];
}
/**
* Get javascript settings.
*
* @param \Drupal\editor\Entity\Editor $editor
* A configured text editor object.
*/
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;
}
/**
* {@inheritdoc}
*/
public function getLibraries(Editor $editor) {
$libraries = [
'gutenberg/edit-node',
// Media attributes overrides must come after all
// Gutenberg initialization.
'gutenberg/g-media-attributes',
'gutenberg/blocks-edit',
'gutenberg/drupal-blocks',
];
return $libraries;
}
/**
* Builds the "toolbar" configuration part of the CKEditor JS settings.
*
* @param \Drupal\editor\Entity\Editor $editor
* A configured text editor object.
*
* @return array
* An array containing the "toolbar" configuration.
*
* @see getJsSettings()
*/
public function buildToolbarJsSetting(Editor $editor) {
$toolbar = [];
return $toolbar;
}
/**
* Builds the "contentsCss" configuration part of the CKEditor JS settings.
*
* @param \Drupal\editor\Entity\Editor $editor
* A configured text editor object.
*
* @return array
* An array containing the "contentsCss" configuration.
*
* @see getJsSettings()
*/
public function buildContentsCssJsSetting(Editor $editor) {
return [];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
EditorBase:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
3 |
EditorBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
1 |
EditorBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
1 |
EditorPluginInterface:: |
public | function | Returns JavaScript settings to be attached. | 4 |
Gutenberg:: |
protected | property | The Gutenberg plugin manager. | |
Gutenberg:: |
protected | property | The language manager. | |
Gutenberg:: |
protected | property | The module handler to invoke hooks on. | |
Gutenberg:: |
protected | property | Drupal\Core\Render\RendererInterface instance. | |
Gutenberg:: |
public | function | Builds the "contentsCss" configuration part of the CKEditor JS settings. | |
Gutenberg:: |
public | function | Builds the "toolbar" configuration part of the CKEditor JS settings. | |
Gutenberg:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
Gutenberg:: |
public | function |
Returns the default settings for this configurable text editor. Overrides EditorBase:: |
|
Gutenberg:: |
public | function | Get javascript settings. | |
Gutenberg:: |
public | function | Returns a list of language codes supported by CKEditor. | |
Gutenberg:: |
public | function |
Returns libraries to be attached. Overrides EditorPluginInterface:: |
|
Gutenberg:: |
public | function | ||
Gutenberg:: |
public | function |
Constructs a Gutenberg object. Overrides PluginBase:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |