EditorSelector.php in Drupal 9
File
core/modules/quickedit/src/EditorSelector.php
View source
<?php
namespace Drupal\quickedit;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterPluginManager;
class EditorSelector implements EditorSelectorInterface {
protected $editorManager;
protected $formatterManager;
protected $alternatives;
public function __construct(PluginManagerInterface $editor_manager, FormatterPluginManager $formatter_manager) {
$this->editorManager = $editor_manager;
$this->formatterManager = $formatter_manager;
}
public function getEditor($formatter_type, FieldItemListInterface $items) {
$formatter_info = $this->formatterManager
->getDefinition($formatter_type);
$editor_id = $formatter_info['quickedit']['editor'];
if ($editor_id === 'disabled') {
return;
}
elseif ($editor_id === 'form') {
return 'form';
}
$editor_choices = [
$editor_id,
];
if (isset($this->alternatives[$editor_id])) {
$editor_choices = array_merge($editor_choices, $this->alternatives[$editor_id]);
}
foreach ($editor_choices as $editor_id) {
$editor = $this->editorManager
->createInstance($editor_id);
if ($editor
->isCompatible($items)) {
return $editor_id;
}
}
return 'form';
}
public function getEditorAttachments(array $editor_ids) {
$attachments = [];
$editor_ids = array_unique($editor_ids);
foreach ($editor_ids as $editor_id) {
$editor = $this->editorManager
->createInstance($editor_id);
$attachments[] = $editor
->getAttachments();
}
return NestedArray::mergeDeepArray($attachments);
}
}
Classes
Name |
Description |
EditorSelector |
Selects an in-place editor (an InPlaceEditor plugin) for a field. |